Documentation ¶
Index ¶
- Constants
- func TestLocalProvider(t *testing.T, b *Local, name string, schema *terraform.ProviderSchema) *terraform.MockProvider
- func TestNewLocalNoDefault() backend.Backend
- func TestNewLocalSingle() backend.Backend
- type CountHook
- func (h *CountHook) PostApply(addr addrs.AbsResourceInstance, gen states.Generation, newState cty.Value, ...) (terraform.HookAction, error)
- func (h *CountHook) PostDiff(addr addrs.AbsResourceInstance, gen states.Generation, action plans.Action, ...) (terraform.HookAction, error)
- func (h *CountHook) PreApply(addr addrs.AbsResourceInstance, gen states.Generation, action plans.Action, ...) (terraform.HookAction, error)
- func (h *CountHook) Reset()
- type Local
- func (b *Local) CLIInit(opts *backend.CLIOpts) error
- func (b *Local) Colorize() *colorstring.Colorize
- func (b *Local) ConfigSchema() *configschema.Block
- func (b *Local) Configure(obj cty.Value) tfdiags.Diagnostics
- func (b *Local) Context(op *backend.Operation) (*terraform.Context, statemgr.Full, tfdiags.Diagnostics)
- func (b *Local) DeleteWorkspace(name string) error
- func (b *Local) Operation(ctx context.Context, op *backend.Operation) (*backend.RunningOperation, error)
- func (b *Local) PathsConflictWith(other *Local) bool
- func (b *Local) ReportResult(op *backend.RunningOperation, diags tfdiags.Diagnostics)
- func (b *Local) StateMgr(name string) (statemgr.Full, error)
- func (b *Local) StatePaths(name string) (stateIn, stateOut, backupOut string)
- func (b *Local) ValidateConfig(obj cty.Value) tfdiags.Diagnostics
- func (b *Local) Workspaces() ([]string, error)
- type StateHook
- type TestLocalNoDefaultState
- type TestLocalSingleState
Constants ¶
const ( DefaultWorkspaceDir = "terraform.tfstate.d" DefaultWorkspaceFile = "environment" DefaultStateFilename = "terraform.tfstate" DefaultBackupExtension = ".backup" )
Variables ¶
This section is empty.
Functions ¶
func TestLocalProvider ¶
func TestLocalProvider(t *testing.T, b *Local, name string, schema *terraform.ProviderSchema) *terraform.MockProvider
TestLocalProvider modifies the ContextOpts of the *Local parameter to have a provider with the given name.
func TestNewLocalNoDefault ¶ added in v0.11.8
TestNewLocalNoDefault is a factory for creating a TestLocalNoDefaultState. This function matches the signature required for backend/init.
func TestNewLocalSingle ¶
TestNewLocalSingle is a factory for creating a TestLocalSingleState. This function matches the signature required for backend/init.
Types ¶
type CountHook ¶
type CountHook struct { Added int Changed int Removed int ToAdd int ToChange int ToRemove int ToRemoveAndAdd int sync.Mutex terraform.NilHook // contains filtered or unexported fields }
CountHook is a hook that counts the number of resources added, removed, changed during the course of an apply.
func (*CountHook) PostApply ¶
func (h *CountHook) PostApply(addr addrs.AbsResourceInstance, gen states.Generation, newState cty.Value, err error) (terraform.HookAction, error)
func (*CountHook) PostDiff ¶
func (h *CountHook) PostDiff(addr addrs.AbsResourceInstance, gen states.Generation, action plans.Action, priorState, plannedNewState cty.Value) (terraform.HookAction, error)
func (*CountHook) PreApply ¶
func (h *CountHook) PreApply(addr addrs.AbsResourceInstance, gen states.Generation, action plans.Action, priorState, plannedNewState cty.Value) (terraform.HookAction, error)
type Local ¶
type Local struct { // CLI and Colorize control the CLI output. If CLI is nil then no CLI // output will be done. If CLIColor is nil then no coloring will be done. CLI cli.Ui CLIColor *colorstring.Colorize // ShowDiagnostics prints diagnostic messages to the UI. ShowDiagnostics func(vals ...interface{}) // The State* paths are set from the backend config, and may be left blank // to use the defaults. If the actual paths for the local backend state are // needed, use the StatePaths method. // // StatePath is the local path where state is read from. // // StateOutPath is the local path where the state will be written. // If this is empty, it will default to StatePath. // // StateBackupPath is the local path where a backup file will be written. // Set this to "-" to disable state backup. // // StateWorkspaceDir is the path to the folder containing data for // non-default workspaces. This defaults to DefaultWorkspaceDir if not set. StatePath string StateOutPath string StateBackupPath string StateWorkspaceDir string // The OverrideState* paths are set based on per-operation CLI arguments // and will override what'd be built from the State* fields if non-empty. // While the interpretation of the State* fields depends on the active // workspace, the OverrideState* fields are always used literally. OverrideStatePath string OverrideStateOutPath string OverrideStateBackupPath string // Terraform context. Many of these will be overridden or merged by // Operation. See Operation for more details. ContextOpts *terraform.ContextOpts // OpInput will ask for necessary input prior to performing any operations. // // OpValidation will perform validation prior to running an operation. The // variable naming doesn't match the style of others since we have a func // Validate. OpInput bool OpValidation bool // Backend, if non-nil, will use this backend for non-enhanced behavior. // This allows local behavior with remote state storage. It is a way to // "upgrade" a non-enhanced backend to an enhanced backend with typical // behavior. // // If this is nil, local performs normal state loading and storage. Backend backend.Backend // RunningInAutomation indicates that commands are being run by an // automated system rather than directly at a command prompt. // // This is a hint not to produce messages that expect that a user can // run a follow-up command, perhaps because Terraform is running in // some sort of workflow automation tool that abstracts away the // exact commands that are being run. RunningInAutomation bool // contains filtered or unexported fields }
Local is an implementation of EnhancedBackend that performs all operations locally. This is the "default" backend and implements normal Terraform behavior as it is well known.
func NewWithBackend ¶ added in v0.11.8
NewWithBackend returns a new local backend initialized with a dedicated backend for non-enhanced behavior.
func TestLocal ¶
TestLocal returns a configured Local struct with temporary paths and in-memory ContextOpts.
No operations will be called on the returned value, so you can still set public fields without any locks.
func (*Local) Colorize ¶
func (b *Local) Colorize() *colorstring.Colorize
Colorize returns the Colorize structure that can be used for colorizing output. This is gauranteed to always return a non-nil value and so is useful as a helper to wrap any potentially colored strings.
func (*Local) ConfigSchema ¶ added in v0.12.0
func (b *Local) ConfigSchema() *configschema.Block
func (*Local) Context ¶
func (b *Local) Context(op *backend.Operation) (*terraform.Context, statemgr.Full, tfdiags.Diagnostics)
backend.Local implementation.
func (*Local) DeleteWorkspace ¶ added in v0.12.0
DeleteWorkspace removes a workspace.
The "default" workspace cannot be removed.
func (*Local) Operation ¶
func (b *Local) Operation(ctx context.Context, op *backend.Operation) (*backend.RunningOperation, error)
Operation implements backend.Enhanced
This will initialize an in-memory terraform.Context to perform the operation within this process.
The given operation parameter will be merged with the ContextOpts on the structure with the following rules. If a rule isn't specified and the name conflicts, assume that the field is overwritten if set.
func (*Local) PathsConflictWith ¶ added in v0.12.0
PathsConflictWith returns true if any state path used by a workspace in the receiver is the same as any state path used by the other given local backend instance.
This should be used when "migrating" from one local backend configuration to another in order to avoid deleting the "old" state snapshots if they are in the same files as the "new" state snapshots.
func (*Local) ReportResult ¶ added in v0.12.0
func (b *Local) ReportResult(op *backend.RunningOperation, diags tfdiags.Diagnostics)
ReportResult is a helper for the common chore of setting the status of a running operation and showing any diagnostics produced during that operation.
If the given diagnostics contains errors then the operation's result will be set to backend.OperationFailure. It will be set to backend.OperationSuccess otherwise. It will then use b.ShowDiagnostics to show the given diagnostics before returning.
Callers should feel free to do each of these operations separately in more complex cases where e.g. diagnostics are interleaved with other output, but terminating immediately after reporting error diagnostics is common and can be expressed concisely via this method.
func (*Local) StatePaths ¶
StatePaths returns the StatePath, StateOutPath, and StateBackupPath as configured from the CLI.
func (*Local) ValidateConfig ¶
func (b *Local) ValidateConfig(obj cty.Value) tfdiags.Diagnostics
func (*Local) Workspaces ¶ added in v0.12.0
type StateHook ¶
StateHook is a hook that continuously updates the state by calling WriteState on a state.State.
func (*StateHook) PostStateUpdate ¶
type TestLocalNoDefaultState ¶ added in v0.11.8
type TestLocalNoDefaultState struct {
*Local
}
TestLocalNoDefaultState is a backend implementation that wraps Local and modifies it to support named states, but not the default state. It returns ErrDefaultWorkspaceNotSupported when the DefaultStateName is used.
func (*TestLocalNoDefaultState) DeleteWorkspace ¶ added in v0.12.0
func (b *TestLocalNoDefaultState) DeleteWorkspace(name string) error
func (*TestLocalNoDefaultState) StateMgr ¶ added in v0.12.0
func (b *TestLocalNoDefaultState) StateMgr(name string) (statemgr.Full, error)
func (*TestLocalNoDefaultState) Workspaces ¶ added in v0.12.0
func (b *TestLocalNoDefaultState) Workspaces() ([]string, error)
type TestLocalSingleState ¶
type TestLocalSingleState struct {
*Local
}
TestLocalSingleState is a backend implementation that wraps Local and modifies it to only support single states (returns ErrWorkspacesNotSupported for multi-state operations).
This isn't an actual use case, this is exported just to provide a easy way to test that behavior.
func (*TestLocalSingleState) DeleteWorkspace ¶ added in v0.12.0
func (b *TestLocalSingleState) DeleteWorkspace(string) error
func (*TestLocalSingleState) StateMgr ¶ added in v0.12.0
func (b *TestLocalSingleState) StateMgr(name string) (statemgr.Full, error)
func (*TestLocalSingleState) Workspaces ¶ added in v0.12.0
func (b *TestLocalSingleState) Workspaces() ([]string, error)