github.com/jpedro/terraform@v0.11.12-beta1/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  // ClientLocker is an optional interface that allows a remote state
    19  // backend to enable state lock/unlock.
    20  type ClientLocker interface {
    21  	Client
    22  	state.Locker
    23  }
    24  
    25  // Payload is the return value from the remote state storage.
    26  type Payload struct {
    27  	MD5  []byte
    28  	Data []byte
    29  }
    30  
    31  // Factory is the factory function to create a remote client.
    32  type Factory func(map[string]string) (Client, error)
    33  
    34  // NewClient returns a new Client with the given type and configuration.
    35  // The client is looked up in the BuiltinClients variable.
    36  func NewClient(t string, conf map[string]string) (Client, error) {
    37  	f, ok := BuiltinClients[t]
    38  	if !ok {
    39  		return nil, fmt.Errorf("unknown remote client type: %s", t)
    40  	}
    41  
    42  	return f(conf)
    43  }
    44  
    45  // BuiltinClients is the list of built-in clients that can be used with
    46  // NewClient.
    47  var BuiltinClients = map[string]Factory{
    48  	"artifactory": artifactoryFactory,
    49  	"etcd":        etcdFactory,
    50  	"http":        httpFactory,
    51  	"local":       fileFactory,
    52  }