diff --git a/remote/client.go b/remote/client.go index bf9986500..c57e40c78 100644 --- a/remote/client.go +++ b/remote/client.go @@ -3,6 +3,8 @@ package remote import ( "fmt" "strings" + + "github.com/hashicorp/terraform/terraform" ) var ( @@ -40,6 +42,12 @@ type RemoteStatePayload struct { State []byte } +// NewClientByState is used to construct a client from +// our remote state. +func NewClientByState(remote *terraform.RemoteState) (RemoteClient, error) { + return NewClientByType(remote.Type, remote.Config) +} + // NewClientByType is used to construct a RemoteClient // based on the configured type. func NewClientByType(ctype string, conf map[string]string) (RemoteClient, error) { diff --git a/remote/remote.go b/remote/remote.go index 1651f6263..11a47c2da 100644 --- a/remote/remote.go +++ b/remote/remote.go @@ -188,7 +188,7 @@ func ValidConfig(conf *terraform.RemoteState) error { if conf.Type == "" { conf.Type = "atlas" } - _, err := NewClientByType(conf.Type, conf.Config) + _, err := NewClientByState(conf) if err != nil { return err } @@ -228,7 +228,7 @@ func RefreshState(conf *terraform.RemoteState) (StateChangeResult, error) { } // Read the state from the server - client, err := NewClientByType(conf.Type, conf.Config) + client, err := NewClientByState(conf) if err != nil { return StateChangeNoop, fmt.Errorf("Failed to create remote client: %v", err) @@ -334,7 +334,7 @@ func PushState(conf *terraform.RemoteState, force bool) (StateChangeResult, erro } // Push the state to the server - client, err := NewClientByType(conf.Type, conf.Config) + client, err := NewClientByState(conf) if err != nil { return StateChangeNoop, fmt.Errorf("Failed to create remote client: %v", err)