From 1ec0602cab7937e3ef61feca0462c0e3ab738fb1 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Tue, 30 Sep 2014 13:29:50 -0700 Subject: [PATCH] terraform: Add new remote storage fields to state --- terraform/state.go | 37 +++++++++++++++++++++++++++++++++++++ terraform/state_test.go | 5 +++++ 2 files changed, 42 insertions(+) diff --git a/terraform/state.go b/terraform/state.go index eb985c37a..ac7269bc2 100644 --- a/terraform/state.go +++ b/terraform/state.go @@ -34,6 +34,10 @@ type State struct { // updates. Serial int64 `json:"serial"` + // Remote is used to track the metadata required to + // pull and push state files from a remote storage endpoint. + Remote *RemoteState `json:"remote,omitempty"` + // Modules contains all the modules in a breadth-first order Modules []*ModuleState `json:"modules"` } @@ -123,6 +127,9 @@ func (s *State) deepcopy() *State { for _, mod := range s.Modules { n.Modules = append(n.Modules, mod.deepcopy()) } + if s.Remote != nil { + n.Remote = s.Remote.deepcopy() + } return n } @@ -134,6 +141,9 @@ func (s *State) prune() { for _, mod := range s.Modules { mod.prune() } + if s.Remote != nil && s.Remote.Empty() { + s.Remote = nil + } } // sort sorts the modules @@ -167,6 +177,33 @@ func (s *State) String() string { return strings.TrimSpace(buf.String()) } +// RemoteState is used to track the information about a remote +// state store that we push/pull state to. +type RemoteState struct { + // Name is the name of the project in the remote state store + Name string `json:"name"` + + // Server is the address of the server. Defaults to the public + // hosted version if not provided. + Server string `json:"server,omitempty"` + + // AuthToken is used for optional authentication with the + // server. + AuthToken string `json:"auth_token,omitempty"` +} + +func (r *RemoteState) deepcopy() *RemoteState { + return &RemoteState{ + Name: r.Name, + Server: r.Server, + AuthToken: r.AuthToken, + } +} + +func (r *RemoteState) Empty() bool { + return (r.Name == "" && r.Server == "" && r.AuthToken == "") +} + // ModuleState is used to track all the state relevant to a single // module. Previous to Terraform 0.3, all state belonged to the "root" // module. diff --git a/terraform/state_test.go b/terraform/state_test.go index 57e1308c1..023de45eb 100644 --- a/terraform/state_test.go +++ b/terraform/state_test.go @@ -177,6 +177,11 @@ func TestReadUpgradeState(t *testing.T) { func TestReadWriteState(t *testing.T) { state := &State{ Serial: 9, + Remote: &RemoteState{ + Name: "hashicorp-www", + Server: "http://my-cool-server.com/", + AuthToken: "foobarbaz", + }, Modules: []*ModuleState{ &ModuleState{ Path: rootModulePath,