state

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2015 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TestState

func TestState(t *testing.T, s interface{})

TestState is a helper for testing state implementations. It is expected that the given implementation is pre-loaded with the TestStateInitial state.

func TestStateInitial

func TestStateInitial() *terraform.State

TestStateInitial is the initial state that a State should have for TestState.

Types

type BackupState

type BackupState struct {
	Real State
	Path string
	// contains filtered or unexported fields
}

BackupState wraps a State that backs up the state on the first time that a WriteState or PersistState is called.

If Path exists, it will be overwritten.

func (*BackupState) PersistState

func (s *BackupState) PersistState() error

func (*BackupState) RefreshState

func (s *BackupState) RefreshState() error

func (*BackupState) State

func (s *BackupState) State() *terraform.State

func (*BackupState) WriteState

func (s *BackupState) WriteState(state *terraform.State) error

type CacheRefreshResult

type CacheRefreshResult int

CacheRefreshResult is used to explain the result of the previous RefreshState for a CacheState.

const (
	// CacheRefreshNoop indicates nothing has happened,
	// but that does not indicate an error. Everything is
	// just up to date. (Push/Pull)
	CacheRefreshNoop CacheRefreshResult = iota

	// CacheRefreshInit indicates that there is no local or
	// remote state, and that the state was initialized
	CacheRefreshInit

	// CacheRefreshUpdateLocal indicates the local state
	// was updated. (Pull)
	CacheRefreshUpdateLocal

	// CacheRefreshUpdateRemote indicates the remote state
	// was updated. (Push)
	CacheRefreshUpdateRemote

	// CacheRefreshLocalNewer means the pull was a no-op
	// because the local state is newer than that of the
	// server. This means a Push should take place. (Pull)
	CacheRefreshLocalNewer

	// CacheRefreshRemoteNewer means the push was a no-op
	// because the remote state is newer than that of the
	// local state. This means a Pull should take place.
	// (Push)
	CacheRefreshRemoteNewer

	// CacheRefreshConflict means that the push or pull
	// was a no-op because there is a conflict. This means
	// there are multiple state definitions at the same
	// serial number with different contents. This requires
	// an operator to intervene and resolve the conflict.
	// Shame on the user for doing concurrent apply.
	// (Push/Pull)
	CacheRefreshConflict
)

func (CacheRefreshResult) String

func (sc CacheRefreshResult) String() string

func (CacheRefreshResult) SuccessfulPull

func (sc CacheRefreshResult) SuccessfulPull() bool

SuccessfulPull is used to clasify the CacheRefreshResult for a refresh operation. This is different by operation, but can be used to determine a proper exit code.

type CacheState

type CacheState struct {
	Cache   CacheStateCache
	Durable CacheStateDurable
	// contains filtered or unexported fields
}

CacheState is an implementation of the state interfaces that uses a StateReadWriter for a local cache.

func (*CacheState) PersistState

func (s *CacheState) PersistState() error

PersistState takes the local cache, assuming it is newer than the remote state, and persists it to the durable storage. If you want to challenge the assumption that the local state is the latest, call a RefreshState prior to this.

StatePersister impl.

func (*CacheState) RefreshResult

func (s *CacheState) RefreshResult() CacheRefreshResult

RefreshResult returns the result of the last refresh.

func (*CacheState) RefreshState

func (s *CacheState) RefreshState() error

RefreshState will refresh both the cache and the durable states. It can return a myriad of errors (defined at the top of this file) depending on potential conflicts that can occur while doing this.

If the durable state is newer than the local cache, then the local cache will be replaced with the durable.

StateRefresher impl.

func (*CacheState) State

func (s *CacheState) State() *terraform.State

StateReader impl.

func (*CacheState) WriteState

func (s *CacheState) WriteState(state *terraform.State) error

WriteState will write and persist the state to the cache.

StateWriter impl.

type CacheStateCache

type CacheStateCache interface {
	StateReader
	StateWriter
	StatePersister
	StateRefresher
}

CacheStateCache is the meta-interface that must be implemented for the cache for the CacheState.

type CacheStateDurable

type CacheStateDurable interface {
	StateReader
	StateWriter
	StatePersister
	StateRefresher
}

CacheStateDurable is the meta-interface that must be implemented for the durable storage for CacheState.

type InmemState

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

InmemState is an in-memory state storage.

func (*InmemState) PersistState

func (s *InmemState) PersistState() error

func (*InmemState) RefreshState

func (s *InmemState) RefreshState() error

func (*InmemState) State

func (s *InmemState) State() *terraform.State

func (*InmemState) WriteState

func (s *InmemState) WriteState(state *terraform.State) error

type LocalState

type LocalState struct {
	// Path is the path to read the state from. PathOut is the path to
	// write the state to. If PathOut is not specified, Path will be used.
	// If PathOut already exists, it will be overwritten.
	Path    string
	PathOut string
	// contains filtered or unexported fields
}

LocalState manages a state storage that is local to the filesystem.

func (*LocalState) PersistState

func (s *LocalState) PersistState() error

PersistState for LocalState is a no-op since WriteState always persists.

StatePersister impl.

func (*LocalState) RefreshState

func (s *LocalState) RefreshState() error

StateRefresher impl.

func (*LocalState) SetState

func (s *LocalState) SetState(state *terraform.State)

SetState will force a specific state in-memory for this local state.

func (*LocalState) State

func (s *LocalState) State() *terraform.State

StateReader impl.

func (*LocalState) WriteState

func (s *LocalState) WriteState(state *terraform.State) error

WriteState for LocalState always persists the state as well.

StateWriter impl.

type State

State is the collection of all state interfaces.

type StatePersister

type StatePersister interface {
	PersistState() error
}

StatePersister is implemented to truly persist a state. Whereas StateWriter is allowed to perhaps be caching in memory, PersistState must write the state to some durable storage.

type StateReader

type StateReader interface {
	State() *terraform.State
}

StateReader is the interface for things that can return a state. Retrieving the state here must not error. Loading the state fresh (an operation that can likely error) should be implemented by RefreshState. If a state hasn't been loaded yet, it is okay for State to return nil.

type StateRefresher

type StateRefresher interface {
	RefreshState() error
}

StateRefresher is the interface that is implemented by something that can load a state. This might be refreshing it from a remote location or it might simply be reloading it from disk.

type StateWriter

type StateWriter interface {
	WriteState(*terraform.State) error
}

StateWriter is the interface that must be implemented by something that can write a state. Writing the state can be cached or in-memory, as full persistence should be implemented by StatePersister.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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