Version: v0.15.3 Latest Latest

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

Go to latest
Published: May 6, 2021 License: MPL-2.0 Imports: 17 Imported by: 0



Package state exposes common helpers for working with state from the CLI.

This is a separate package so that backends can use this for consistent messaging without creating a circular reference to the command package.



View Source
const (
	LockThreshold    = 400 * time.Millisecond
	LockErrorMessage = `` /* 273-byte string literal not displayed */

	UnlockErrorMessage = `` /* 722-byte string literal not displayed */



This section is empty.


This section is empty.


type LocalState added in v0.13.1

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) Lock added in v0.13.1

func (s *LocalState) Lock(info *statemgr.LockInfo) (string, error)

Lock implements a local filesystem state.Locker.

func (*LocalState) PersistState added in v0.13.1

func (s *LocalState) PersistState() error

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

StatePersister impl.

func (*LocalState) RefreshState added in v0.13.1

func (s *LocalState) RefreshState() error

StateRefresher impl.

func (*LocalState) SetState added in v0.13.1

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

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

func (*LocalState) State added in v0.13.1

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

StateReader impl.

func (*LocalState) Unlock added in v0.13.1

func (s *LocalState) Unlock(id string) error

func (*LocalState) WriteState added in v0.13.1

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

WriteState for LocalState always persists the state as well. TODO: this should use a more robust method of writing state, by first writing to a temp file on the same filesystem, and renaming the file over the original.

StateWriter impl.

type Locker added in v0.11.4

type Locker interface {
	// Returns a shallow copy of the locker with its context changed to ctx.
	WithContext(ctx context.Context) Locker

	// Lock the provided state manager, storing the reason string in the LockInfo.
	Lock(s statemgr.Locker, reason string) tfdiags.Diagnostics

	// Unlock the previously locked state.
	Unlock() tfdiags.Diagnostics

	// Timeout returns the configured timeout duration
	Timeout() time.Duration

Locker allows for more convenient usage of the lower-level statemgr.Locker implementations. The statemgr.Locker API requires passing in a statemgr.LockInfo struct. Locker implementations are expected to create the required LockInfo struct when Lock is called, populate the Operation field with the "reason" string provided, and pass that on to the underlying statemgr.Locker. Locker implementations are also expected to store any state required to call Unlock, which is at a minimum the LockID string returned by the statemgr.Locker.

func NewLocker added in v0.11.4

func NewLocker(timeout time.Duration, view views.StateLocker) Locker

Create a new Locker. This Locker uses state.LockWithContext to retry the lock until the provided timeout is reached, or the context is canceled. Lock progress will be be reported to the user through the provided UI.

func NewNoopLocker added in v0.11.4

func NewNoopLocker() Locker

NewNoopLocker returns a valid Locker that does nothing.

Jump to

Keyboard shortcuts

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