storage

package
v0.0.0-...-84b5366 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoDocuments = errors.New("No document found")

ErrNoDocuments returns an error when no documents were found in the storage

Functions

This section is empty.

Types

type LockInfo

type LockInfo struct {
	// Unique ID for the lock. NewLockInfo provides a random ID, but this may
	// be overridden by the lock implementation. The final value if ID will be
	// returned by the call to Lock.
	ID string `json:"id,omitempty"`

	// Terraform operation, provided by the caller.
	Operation string `json:"operation,omitempty"`

	// Extra information to store with the lock, provided by the caller.
	Info string `json:"info,omitempty"`

	// user@hostname when available
	Who string `json:"who,omitempty"`

	// Terraform version
	Version string `json:"version,omitempty"`

	// Time that the lock was taken.
	// Use a *time.Time to allow omitempty
	Created *time.Time `json:"created,omitempty"`

	// Path to the state file when applicable. Set by the Lock implementation.
	Path string `json:"path,omitempty"`
}

LockInfo stores lock metadata.

Copied from Terraform's source code to add missing json tags to structure fields

type Metadata

type Metadata struct {
	Total int `json:"total"`
	Page  int `json:"page"`
}

Metadata is a metadata struct

type MongoDBConfig

type MongoDBConfig struct {
	URL      string
	Username string
	Password string
}

MongoDBConfig stores the informations required to connect a MongoDB database.

type MongoDBStorage

type MongoDBStorage struct {
	// contains filtered or unexported fields
}

MongoDBStorage stores the MongoDB client.

func NewMongoDB

func NewMongoDB(config *MongoDBConfig) (st *MongoDBStorage, err error)

NewMongoDB initializes a connection to the defined MongoDB instance.

func (*MongoDBStorage) GetLockStatus

func (st *MongoDBStorage) GetLockStatus(name string) (lockStatus LockInfo, err error)

GetLockStatus returns a Terraform lock.

func (*MongoDBStorage) GetName

func (*MongoDBStorage) GetName() string

GetName returns the storage's name.

func (*MongoDBStorage) GetResource

func (st *MongoDBStorage) GetResource(state, module, name string) (res Resource, err error)

GetResource retrieves a Terraform resource given a state, module and name

func (*MongoDBStorage) GetState

func (st *MongoDBStorage) GetState(name string, serial int) (state State, err error)

GetState retrieves a Terraform state, at a given serial. If serial is 0, it gets the latest serial

func (*MongoDBStorage) InsertState

func (st *MongoDBStorage) InsertState(doc State, timestamp, source, name string) (err error)

InsertState adds a Terraform state to the database.

func (*MongoDBStorage) ListStateSerials

func (st *MongoDBStorage) ListStateSerials(name string, pageNum, pageSize int) (coll StateCollection, err error)

ListStateSerials returns all state serials with a given name.

func (*MongoDBStorage) ListStates

func (st *MongoDBStorage) ListStates(pageNum, pageSize int) (coll StateCollection, err error)

ListStates returns all state names from TerraDB

func (*MongoDBStorage) LockState

func (st *MongoDBStorage) LockState(name string, lockData LockInfo) (err error)

LockState locks a Terraform state.

func (*MongoDBStorage) RemoveState

func (st *MongoDBStorage) RemoveState(name string) (err error)

RemoveState removes the Terraform states.

func (*MongoDBStorage) UnlockState

func (st *MongoDBStorage) UnlockState(name string, lockData LockInfo) (err error)

UnlockState unlocks a Terraform state.

type Resource

type Resource = terraform.ResourceState

Resource models a Terraform Resource

type State

type State struct {
	LastModified time.Time `json:"last_modified"`
	Name         string    `json:"name"`

	// Keep Lock info
	Locked   bool     `json:"locked"`
	LockInfo LockInfo `json:"lock"`

	// Version is the state file protocol version.
	Version int `json:"version"`

	// TFVersion is the version of Terraform that wrote this state.
	TFVersion string `json:"terraform_version,omitempty"`

	// Serial is incremented on any operation that modifies
	// the State file. It is used to detect potentially conflicting
	// updates.
	Serial int64 `json:"serial"`

	// Lineage is set when a new, blank state is created and then
	// never updated. This allows us to determine whether the serials
	// of two states can be meaningfully compared.
	// Apart from the guarantee that collisions between two lineages
	// are very unlikely, this value is opaque and external callers
	// should only compare lineage strings byte-for-byte for equality.
	Lineage string `json:"lineage"`

	// Remote is used to track the metadata required to
	// pull and push state files from a remote storage endpoint.
	Remote *terraform.RemoteState `json:"remote,omitempty"`

	// Backend tracks the configuration for the backend in use with
	// this state. This is used to track any changes in the backend
	// configuration.
	Backend *terraform.BackendState `json:"backend,omitempty"`

	// Modules contains all the modules in a breadth-first order
	Modules []*terraform.ModuleState `json:"modules"`
}

State is a Terraform state

type StateCollection

type StateCollection struct {
	Metadata []*Metadata `json:"metadata"`
	Data     []*State    `json:"data"`
}

StateCollection is a collection of State, with metadata

type Storage

type Storage interface {
	GetName() string
	ListStates(pageNum, pageSize int) (coll StateCollection, err error)
	GetState(name string, serial int) (state State, err error)
	InsertState(document State, timestamp, source, name string) (err error)
	RemoveState(name string) (err error)
	GetLockStatus(name string) (lockStatus LockInfo, err error)
	LockState(name string, lockData LockInfo) (err error)
	UnlockState(name string, lockData LockInfo) (err error)
	ListStateSerials(name string, pageNum, pageSize int) (coll StateCollection, err error)
	GetResource(state, module, name string) (res Resource, err error)
}

Storage is an abstraction over database engines

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL