github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/state/remote/remote.go (about) 1 package remote 2 3 import ( 4 "fmt" 5 6 "github.com/hashicorp/terraform/state" 7 ) 8 9 // Client is the interface that must be implemented for a remote state 10 // driver. It supports dumb put/get/delete, and the higher level structs 11 // handle persisting the state properly here. 12 type Client interface { 13 Get() (*Payload, error) 14 Put([]byte) error 15 Delete() error 16 } 17 18 // ClientForcePusher is an optional interface that allows a remote 19 // state to force push by managing a flag on the client that is 20 // toggled on by a call to EnableForcePush. 21 type ClientForcePusher interface { 22 Client 23 EnableForcePush() 24 } 25 26 // ClientLocker is an optional interface that allows a remote state 27 // backend to enable state lock/unlock. 28 type ClientLocker interface { 29 Client 30 state.Locker 31 } 32 33 // Payload is the return value from the remote state storage. 34 type Payload struct { 35 MD5 []byte 36 Data []byte 37 } 38 39 // Factory is the factory function to create a remote client. 40 type Factory func(map[string]string) (Client, error) 41 42 // NewClient returns a new Client with the given type and configuration. 43 // The client is looked up in the BuiltinClients variable. 44 func NewClient(t string, conf map[string]string) (Client, error) { 45 f, ok := BuiltinClients[t] 46 if !ok { 47 return nil, fmt.Errorf("unknown remote client type: %s", t) 48 } 49 50 return f(conf) 51 } 52 53 // BuiltinClients is the list of built-in clients that can be used with 54 // NewClient. 55 var BuiltinClients = map[string]Factory{}