remote: Simplify RemoteClient setup
This commit is contained in:
parent
c1ecdd1e3d
commit
0c4e4297e1
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue