Skip to content

Commit

Permalink
remote: Simplify RemoteClient setup
Browse files Browse the repository at this point in the history
  • Loading branch information
armon authored and mitchellh committed Dec 10, 2014
1 parent c1ecdd1 commit 0c4e429
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions remote/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package remote
import (
"fmt"
"strings"

"github.com/hashicorp/terraform/terraform"
)

var (
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0c4e429

Please sign in to comment.