2014-10-02 20:48:11 +02:00
|
|
|
package remote
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2014-12-04 05:05:29 +01:00
|
|
|
"strings"
|
2014-12-05 01:57:11 +01:00
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
2014-10-02 20:48:11 +02:00
|
|
|
)
|
|
|
|
|
2014-10-07 02:50:09 +02:00
|
|
|
var (
|
|
|
|
// ErrConflict is used to indicate the upload was rejected
|
|
|
|
// due to a conflict on the state
|
|
|
|
ErrConflict = fmt.Errorf("Conflicting state file")
|
2014-10-07 21:09:51 +02:00
|
|
|
|
2014-10-08 19:28:47 +02:00
|
|
|
// ErrServerNewer is used to indicate the serial number of
|
|
|
|
// the state is newer on the server side
|
|
|
|
ErrServerNewer = fmt.Errorf("Server-side Serial is newer")
|
|
|
|
|
2014-10-07 21:09:51 +02:00
|
|
|
// ErrRequireAuth is used if the remote server requires
|
|
|
|
// authentication and none is provided
|
|
|
|
ErrRequireAuth = fmt.Errorf("Remote server requires authentication")
|
|
|
|
|
|
|
|
// ErrInvalidAuth is used if we provide authentication which
|
|
|
|
// is not valid
|
|
|
|
ErrInvalidAuth = fmt.Errorf("Invalid authentication")
|
|
|
|
|
|
|
|
// ErrRemoteInternal is used if we get an internal error
|
|
|
|
// from the remote server
|
|
|
|
ErrRemoteInternal = fmt.Errorf("Remote server reporting internal error")
|
2014-10-07 02:50:09 +02:00
|
|
|
)
|
|
|
|
|
2014-12-04 05:05:29 +01:00
|
|
|
type RemoteClient interface {
|
|
|
|
GetState() (*RemoteStatePayload, error)
|
|
|
|
PutState(state []byte, force bool) error
|
|
|
|
DeleteState() error
|
|
|
|
}
|
|
|
|
|
2014-10-02 20:48:11 +02:00
|
|
|
// RemoteStatePayload is used to return the remote state
|
|
|
|
// along with associated meta data when we do a remote fetch.
|
|
|
|
type RemoteStatePayload struct {
|
2014-10-03 20:14:12 +02:00
|
|
|
MD5 []byte
|
|
|
|
State []byte
|
2014-10-02 20:48:11 +02:00
|
|
|
}
|
|
|
|
|
2014-12-05 01:57:11 +01:00
|
|
|
// NewClientByState is used to construct a client from
|
|
|
|
// our remote state.
|
|
|
|
func NewClientByState(remote *terraform.RemoteState) (RemoteClient, error) {
|
|
|
|
return NewClientByType(remote.Type, remote.Config)
|
|
|
|
}
|
|
|
|
|
2014-12-04 05:05:29 +01:00
|
|
|
// NewClientByType is used to construct a RemoteClient
|
|
|
|
// based on the configured type.
|
|
|
|
func NewClientByType(ctype string, conf map[string]string) (RemoteClient, error) {
|
|
|
|
ctype = strings.ToLower(ctype)
|
|
|
|
switch ctype {
|
|
|
|
case "atlas":
|
|
|
|
return NewAtlasRemoteClient(conf)
|
|
|
|
case "consul":
|
|
|
|
return NewConsulRemoteClient(conf)
|
|
|
|
case "http":
|
|
|
|
return NewHTTPRemoteClient(conf)
|
2014-10-07 02:50:09 +02:00
|
|
|
default:
|
2014-12-04 05:05:29 +01:00
|
|
|
return nil, fmt.Errorf("Unknown remote client type '%s'", ctype)
|
2014-10-07 02:50:09 +02:00
|
|
|
}
|
|
|
|
}
|