From 0c4e4297e100b9d7decf9c084149440f38ada2ac Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Thu, 4 Dec 2014 16:57:11 -0800 Subject: [PATCH] remote: Simplify RemoteClient setup --- remote/client.go | 8 ++++++++ remote/remote.go | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) 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)