Documentation
¶
Overview ¶
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.
Index ¶
- Constants
- type LocalState
- func (s *LocalState) Lock(info *statemgr.LockInfo) (string, error)
- func (s *LocalState) PersistState() error
- func (s *LocalState) RefreshState() error
- func (s *LocalState) SetState(state *terraform.State)
- func (s *LocalState) State() *terraform.State
- func (s *LocalState) Unlock(id string) error
- func (s *LocalState) WriteState(state *terraform.State) error
- type Locker
Constants ¶
const ( LockThreshold = 400 * time.Millisecond LockErrorMessage = `` /* 273-byte string literal not displayed */ UnlockErrorMessage = `` /* 722-byte string literal not displayed */ )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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) Lock ¶
func (s *LocalState) Lock(info *statemgr.LockInfo) (string, error)
Lock implements a local filesystem state.Locker.
func (*LocalState) PersistState ¶
func (s *LocalState) PersistState() error
PersistState for LocalState is a no-op since WriteState always persists.
StatePersister 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) Unlock ¶
func (s *LocalState) Unlock(id string) error
func (*LocalState) WriteState ¶
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 ¶
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 ¶
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 ¶
func NewNoopLocker() Locker
NewNoopLocker returns a valid Locker that does nothing.