github.com/chalford/terraform@v0.3.7-0.20150113080010-a78c69a8c81f/remote/client.go (about) 1 package remote 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/hashicorp/terraform/terraform" 8 ) 9 10 var ( 11 // ErrConflict is used to indicate the upload was rejected 12 // due to a conflict on the state 13 ErrConflict = fmt.Errorf("Conflicting state file") 14 15 // ErrServerNewer is used to indicate the serial number of 16 // the state is newer on the server side 17 ErrServerNewer = fmt.Errorf("Server-side Serial is newer") 18 19 // ErrRequireAuth is used if the remote server requires 20 // authentication and none is provided 21 ErrRequireAuth = fmt.Errorf("Remote server requires authentication") 22 23 // ErrInvalidAuth is used if we provide authentication which 24 // is not valid 25 ErrInvalidAuth = fmt.Errorf("Invalid authentication") 26 27 // ErrRemoteInternal is used if we get an internal error 28 // from the remote server 29 ErrRemoteInternal = fmt.Errorf("Remote server reporting internal error") 30 ) 31 32 type RemoteClient interface { 33 GetState() (*RemoteStatePayload, error) 34 PutState(state []byte, force bool) error 35 DeleteState() error 36 } 37 38 // RemoteStatePayload is used to return the remote state 39 // along with associated meta data when we do a remote fetch. 40 type RemoteStatePayload struct { 41 MD5 []byte 42 State []byte 43 } 44 45 // NewClientByState is used to construct a client from 46 // our remote state. 47 func NewClientByState(remote *terraform.RemoteState) (RemoteClient, error) { 48 return NewClientByType(remote.Type, remote.Config) 49 } 50 51 // NewClientByType is used to construct a RemoteClient 52 // based on the configured type. 53 func NewClientByType(ctype string, conf map[string]string) (RemoteClient, error) { 54 ctype = strings.ToLower(ctype) 55 switch ctype { 56 case "atlas": 57 return NewAtlasRemoteClient(conf) 58 case "consul": 59 return NewConsulRemoteClient(conf) 60 case "http": 61 return NewHTTPRemoteClient(conf) 62 default: 63 return nil, fmt.Errorf("Unknown remote client type '%s'", ctype) 64 } 65 }