terraform: Add new remote storage fields to state

This commit is contained in:
Armon Dadgar 2014-09-30 13:29:50 -07:00 committed by Mitchell Hashimoto
parent 04eb1885f1
commit 1ec0602cab
2 changed files with 42 additions and 0 deletions

View File

@ -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.

View File

@ -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,