terraform

package
v0.14.5 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2021 License: MPL-2.0 Imports: 56 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StateVersion is the current version for our state file
	StateVersion = 3
)

Variables

View Source
var ErrNoState = errors.New("no state")

ErrNoState is returned by ReadState when the io.Reader contains no data

View Source
var EvalDataForNoInstanceKey = InstanceKeyEvalData{}

EvalDataForNoInstanceKey is a value of InstanceKeyData that sets no instance key values at all, suitable for use in contexts where no keyed instance is relevant.

View Source
var GraphTypeMap = map[string]GraphType{
	"apply":        GraphTypeApply,
	"plan":         GraphTypePlan,
	"plan-destroy": GraphTypePlanDestroy,
	"validate":     GraphTypeValidate,
	"eval":         GraphTypeEval,
}

GraphTypeMap is a mapping of human-readable string to GraphType. This is useful to use as the mechanism for human input for configurable graph types.

Functions

func CheckCoreVersionRequirements added in v0.12.0

func CheckCoreVersionRequirements(config *configs.Config) tfdiags.Diagnostics

CheckCoreVersionRequirements visits each of the modules in the given configuration tree and verifies that any given Core version constraints match with the version of Terraform Core that is being used.

The returned diagnostics will contain errors if any constraints do not match. The returned diagnostics might also return warnings, which should be displayed to the user.

func ConnectionBlockSupersetSchema added in v0.12.0

func ConnectionBlockSupersetSchema() *configschema.Block

connectionBlockSupersetSchema is a schema representing the superset of all possible arguments for "connection" blocks across all supported connection types.

This currently lives here because we've not yet updated our communicator subsystem to be aware of schema itself. It's exported only for use in the configs/configupgrade package and should not be used from anywhere else. The caller may not modify any part of the returned schema data structure.

func GraphDot

func GraphDot(g *Graph, opts *dag.DotOpts) (string, error)

GraphDot returns the dot formatting of a visual representation of the given Terraform graph.

func MustShimLegacyState added in v0.12.0

func MustShimLegacyState(legacy *State) *states.State

MustShimLegacyState is a wrapper around ShimLegacyState that panics if the conversion does not succeed. This is primarily intended for tests where the given legacy state is an object constructed within the test.

func ParseResourceIndex added in v0.5.0

func ParseResourceIndex(s string) (int, error)

func ParseResourcePath added in v0.5.0

func ParseResourcePath(s string) []string

func ProviderHasDataSource added in v0.7.0

func ProviderHasDataSource(p ResourceProvider, n string) bool

func ProviderHasResource added in v0.7.0

func ProviderHasResource(p ResourceProvider, n string) bool

func ReadStateV1 added in v0.3.0

func ReadStateV1(jsonBytes []byte) (*stateV1, error)

func ReferencesFromConfig added in v0.7.8

func ReferencesFromConfig(body hcl.Body, schema *configschema.Block) []*addrs.Reference

ReferencesFromConfig returns the references that a configuration has based on the interpolated variables in a configuration.

func ShimLegacyState added in v0.12.0

func ShimLegacyState(legacy *State) (*states.State, error)

ShimLegacyState is a helper that takes the legacy state type and converts it to the new state type.

This is implemented as a state file upgrade, so it will not preserve parts of the state structure that are not included in a serialized state, such as the resolved results of any local values, outputs in non-root modules, etc.

func TestStateFile added in v0.9.0

func TestStateFile(t *testing.T, path string, state *State)

TestStateFile writes the given state to the path.

func UpdateStateHook added in v0.14.0

func UpdateStateHook(ctx EvalContext) error

UpdateStateHook calls the PostStateUpdate hook with the current state.

func UpgradeResourceState added in v0.12.0

func UpgradeResourceState(addr addrs.AbsResourceInstance, provider providers.Interface, src *states.ResourceInstanceObjectSrc, currentSchema *configschema.Block, currentVersion uint64) (*states.ResourceInstanceObjectSrc, tfdiags.Diagnostics)

UpgradeResourceState will, if necessary, run the provider-defined upgrade logic against the given state object to make it compliant with the current schema version. This is a no-op if the given state object is already at the latest version.

If any errors occur during upgrade, error diagnostics are returned. In that case it is not safe to proceed with using the original state object.

func VersionString deprecated added in v0.7.0

func VersionString() string

Deprecated: Providers should use schema.Provider.TerraformVersion instead

func WritePlan

func WritePlan(d *Plan, dst io.Writer) error

WritePlan writes a plan somewhere in a binary format.

func WriteState

func WriteState(d *State, dst io.Writer) error

WriteState writes a state somewhere in a binary format.

Types

type ApplyGraphBuilder added in v0.7.8

type ApplyGraphBuilder struct {
	// Config is the configuration tree that the diff was built from.
	Config *configs.Config

	// Changes describes the changes that we need apply.
	Changes *plans.Changes

	// State is the current state
	State *states.State

	// Components is a factory for the plug-in components (providers and
	// provisioners) available for use.
	Components contextComponentFactory

	// Schemas is the repository of schemas we will draw from to analyse
	// the configuration.
	Schemas *Schemas

	// Targets are resources to target. This is only required to make sure
	// unnecessary outputs aren't included in the apply graph. The plan
	// builder successfully handles targeting resources. In the future,
	// outputs should go into the diff so that this is unnecessary.
	Targets []addrs.Targetable

	// Validate will do structural validation of the graph.
	Validate bool
}

ApplyGraphBuilder implements GraphBuilder and is responsible for building a graph for applying a Terraform diff.

Because the graph is built from the diff (vs. the config or state), this helps ensure that the apply-time graph doesn't modify any resources that aren't explicitly in the diff. There are other scenarios where the diff can be deviated, so this is just one layer of protection.

func (*ApplyGraphBuilder) Build added in v0.7.8

See GraphBuilder

func (*ApplyGraphBuilder) Steps added in v0.7.8

func (b *ApplyGraphBuilder) Steps() []GraphTransformer

See GraphBuilder

type AttachDependenciesTransformer added in v0.12.14

type AttachDependenciesTransformer struct {
}

AttachDependenciesTransformer records all resource dependencies for each instance, and attaches the addresses to the node itself. Managed resource will record these in the state for proper ordering of destroy operations.

func (AttachDependenciesTransformer) Transform added in v0.12.14

func (t AttachDependenciesTransformer) Transform(g *Graph) error

type AttachResourceConfigTransformer added in v0.7.8

type AttachResourceConfigTransformer struct {
	Config *configs.Config // Config is the root node in the config tree
}

AttachResourceConfigTransformer goes through the graph and attaches resource configuration structures to nodes that implement GraphNodeAttachManagedResourceConfig or GraphNodeAttachDataResourceConfig.

The attached configuration structures are directly from the configuration. If they're going to be modified, a copy should be made.

func (*AttachResourceConfigTransformer) Transform added in v0.7.8

func (t *AttachResourceConfigTransformer) Transform(g *Graph) error

type AttachSchemaTransformer added in v0.12.0

type AttachSchemaTransformer struct {
	Schemas *Schemas
	Config  *configs.Config
}

AttachSchemaTransformer finds nodes that implement GraphNodeAttachResourceSchema, GraphNodeAttachProviderConfigSchema, or GraphNodeAttachProvisionerSchema, looks up the needed schemas for each and then passes them to a method implemented by the node.

func (*AttachSchemaTransformer) Transform added in v0.12.0

func (t *AttachSchemaTransformer) Transform(g *Graph) error

type AttachStateTransformer added in v0.7.8

type AttachStateTransformer struct {
	State *states.State // State is the root state
}

AttachStateTransformer goes through the graph and attaches state to nodes that implement the interfaces above.

func (*AttachStateTransformer) Transform added in v0.7.8

func (t *AttachStateTransformer) Transform(g *Graph) error

type BackendState added in v0.9.0

type BackendState struct {
	Type      string          `json:"type"`   // Backend type
	ConfigRaw json.RawMessage `json:"config"` // Backend raw config
	Hash      uint64          `json:"hash"`   // Hash of portion of configuration from config files
}

BackendState stores the configuration to connect to a remote backend.

func (*BackendState) Config added in v0.9.0

func (s *BackendState) Config(schema *configschema.Block) (cty.Value, error)

Config decodes the type-specific configuration object using the provided schema and returns the result as a cty.Value.

An error is returned if the stored configuration does not conform to the given schema.

func (*BackendState) Empty added in v0.9.0

func (s *BackendState) Empty() bool

Empty returns true if BackendState has no state.

func (*BackendState) ForPlan added in v0.12.0

func (s *BackendState) ForPlan(schema *configschema.Block, workspaceName string) (*plans.Backend, error)

ForPlan produces an alternative representation of the reciever that is suitable for storing in a plan. The current workspace must additionally be provided, to be stored alongside the backend configuration.

The backend configuration schema is required in order to properly encode the backend-specific configuration settings.

func (*BackendState) SetConfig added in v0.12.0

func (s *BackendState) SetConfig(val cty.Value, schema *configschema.Block) error

SetConfig replaces (in-place) the type-specific configuration object using the provided value and associated schema.

An error is returned if the given value does not conform to the implied type of the schema.

type BasicGraphBuilder added in v0.4.0

type BasicGraphBuilder struct {
	Steps    []GraphTransformer
	Validate bool
	// Optional name to add to the graph debug log
	Name string
}

BasicGraphBuilder is a GraphBuilder that builds a graph out of a series of transforms and (optionally) validates the graph is a valid structure.

func (*BasicGraphBuilder) Build added in v0.4.0

type BuiltinEvalContext added in v0.4.0

type BuiltinEvalContext struct {
	// StopContext is the context used to track whether we're complete
	StopContext context.Context

	// PathValue is the Path that this context is operating within.
	PathValue addrs.ModuleInstance

	// Evaluator is used for evaluating expressions within the scope of this
	// eval context.
	Evaluator *Evaluator

	// Schemas is a repository of all of the schemas we should need to
	// decode configuration blocks and expressions. This must be constructed by
	// the caller to include schemas for all of the providers, resource types,
	// data sources and provisioners used by the given configuration and
	// state.
	//
	// This must not be mutated during evaluation.
	Schemas *Schemas

	// VariableValues contains the variable values across all modules. This
	// structure is shared across the entire containing context, and so it
	// may be accessed only when holding VariableValuesLock.
	// The keys of the first level of VariableValues are the string
	// representations of addrs.ModuleInstance values. The second-level keys
	// are variable names within each module instance.
	VariableValues     map[string]map[string]cty.Value
	VariableValuesLock *sync.Mutex

	Components            contextComponentFactory
	Hooks                 []Hook
	InputValue            UIInput
	ProviderCache         map[string]providers.Interface
	ProviderInputConfig   map[string]map[string]cty.Value
	ProviderLock          *sync.Mutex
	ProvisionerCache      map[string]provisioners.Interface
	ProvisionerLock       *sync.Mutex
	ChangesValue          *plans.ChangesSync
	StateValue            *states.SyncState
	RefreshStateValue     *states.SyncState
	InstanceExpanderValue *instances.Expander
	// contains filtered or unexported fields
}

BuiltinEvalContext is an EvalContext implementation that is used by Terraform by default.

func (*BuiltinEvalContext) Changes added in v0.12.0

func (ctx *BuiltinEvalContext) Changes() *plans.ChangesSync

func (*BuiltinEvalContext) CloseProvider added in v0.6.0

func (ctx *BuiltinEvalContext) CloseProvider(addr addrs.AbsProviderConfig) error

func (*BuiltinEvalContext) CloseProvisioner added in v0.6.0

func (ctx *BuiltinEvalContext) CloseProvisioner(n string) error

func (*BuiltinEvalContext) ConfigureProvider added in v0.4.0

func (ctx *BuiltinEvalContext) ConfigureProvider(addr addrs.AbsProviderConfig, cfg cty.Value) tfdiags.Diagnostics

func (*BuiltinEvalContext) EvaluateBlock added in v0.12.0

func (ctx *BuiltinEvalContext) EvaluateBlock(body hcl.Body, schema *configschema.Block, self addrs.Referenceable, keyData InstanceKeyEvalData) (cty.Value, hcl.Body, tfdiags.Diagnostics)

func (*BuiltinEvalContext) EvaluateExpr added in v0.12.0

func (ctx *BuiltinEvalContext) EvaluateExpr(expr hcl.Expression, wantType cty.Type, self addrs.Referenceable) (cty.Value, tfdiags.Diagnostics)

func (*BuiltinEvalContext) EvaluationScope added in v0.12.0

func (ctx *BuiltinEvalContext) EvaluationScope(self addrs.Referenceable, keyData InstanceKeyEvalData) *lang.Scope

func (*BuiltinEvalContext) GetVariableValue added in v0.12.20

func (ctx *BuiltinEvalContext) GetVariableValue(addr addrs.AbsInputVariableInstance) cty.Value

func (*BuiltinEvalContext) Hook added in v0.4.0

func (ctx *BuiltinEvalContext) Hook(fn func(Hook) (HookAction, error)) error

func (*BuiltinEvalContext) InitProvider added in v0.4.0

func (*BuiltinEvalContext) InitProvisioner added in v0.4.0

func (ctx *BuiltinEvalContext) InitProvisioner(n string) error

func (*BuiltinEvalContext) Input added in v0.4.0

func (ctx *BuiltinEvalContext) Input() UIInput

func (*BuiltinEvalContext) InstanceExpander added in v0.13.0

func (ctx *BuiltinEvalContext) InstanceExpander() *instances.Expander

func (*BuiltinEvalContext) Path added in v0.4.0

func (*BuiltinEvalContext) Provider added in v0.4.0

func (*BuiltinEvalContext) ProviderInput added in v0.4.0

func (ctx *BuiltinEvalContext) ProviderInput(pc addrs.AbsProviderConfig) map[string]cty.Value

func (*BuiltinEvalContext) ProviderSchema added in v0.12.0

func (ctx *BuiltinEvalContext) ProviderSchema(addr addrs.AbsProviderConfig) *ProviderSchema

func (*BuiltinEvalContext) Provisioner added in v0.4.0

func (ctx *BuiltinEvalContext) Provisioner(n string) provisioners.Interface

func (*BuiltinEvalContext) ProvisionerSchema added in v0.12.0

func (ctx *BuiltinEvalContext) ProvisionerSchema(n string) *configschema.Block

func (*BuiltinEvalContext) RefreshState added in v0.14.0

func (ctx *BuiltinEvalContext) RefreshState() *states.SyncState

func (*BuiltinEvalContext) SetModuleCallArguments added in v0.12.0

func (ctx *BuiltinEvalContext) SetModuleCallArguments(n addrs.ModuleCallInstance, vals map[string]cty.Value)

func (*BuiltinEvalContext) SetProviderInput added in v0.4.0

func (ctx *BuiltinEvalContext) SetProviderInput(pc addrs.AbsProviderConfig, c map[string]cty.Value)

func (*BuiltinEvalContext) State added in v0.4.0

func (ctx *BuiltinEvalContext) State() *states.SyncState

func (*BuiltinEvalContext) Stopped added in v0.9.0

func (ctx *BuiltinEvalContext) Stopped() <-chan struct{}

func (*BuiltinEvalContext) WithPath added in v0.13.0

func (ctx *BuiltinEvalContext) WithPath(path addrs.ModuleInstance) EvalContext

type CBDEdgeTransformer added in v0.7.8

type CBDEdgeTransformer struct {
	// Module and State are only needed to look up dependencies in
	// any way possible. Either can be nil if not availabile.
	Config *configs.Config
	State  *states.State

	// If configuration is present then Schemas is required in order to
	// obtain schema information from providers and provisioners so we can
	// properly resolve implicit dependencies.
	Schemas *Schemas
}

CBDEdgeTransformer modifies the edges of CBD nodes that went through the DestroyEdgeTransformer to have the right dependencies. There are two real tasks here:

  1. With CBD, the destroy edge is inverted: the destroy depends on the creation.

  2. A_d must depend on resources that depend on A. This is to enable the destroy to only happen once nodes that depend on A successfully update to A. Example: adding a web server updates the load balancer before deleting the old web server.

This transformer requires that a previous transformer has already forced create_before_destroy on for nodes that are depended on by explicit CBD nodes. This is the logic in ForcedCBDTransformer, though in practice we will get here by recording the CBD-ness of each change in the plan during the plan walk and then forcing the nodes into the appropriate setting during DiffTransformer when building the apply graph.

func (*CBDEdgeTransformer) Transform added in v0.7.8

func (t *CBDEdgeTransformer) Transform(g *Graph) error

type CallbackUIOutput added in v0.3.0

type CallbackUIOutput struct {
	OutputFn func(string)
}

func (*CallbackUIOutput) Output added in v0.4.0

func (o *CallbackUIOutput) Output(v string)

type CloseProviderTransformer added in v0.6.0

type CloseProviderTransformer struct{}

CloseProviderTransformer is a GraphTransformer that adds nodes to the graph that will close open provider connections that aren't needed anymore. A provider connection is not needed anymore once all depended resources in the graph are evaluated.

func (*CloseProviderTransformer) Transform added in v0.6.0

func (t *CloseProviderTransformer) Transform(g *Graph) error

type CloseProvisionerTransformer added in v0.6.0

type CloseProvisionerTransformer struct{}

CloseProvisionerTransformer is a GraphTransformer that adds nodes to the graph that will close open provisioner connections that aren't needed anymore. A provisioner connection is not needed anymore once all depended resources in the graph are evaluated.

func (*CloseProvisionerTransformer) Transform added in v0.6.0

func (t *CloseProvisionerTransformer) Transform(g *Graph) error

type CloseRootModuleTransformer added in v0.13.0

type CloseRootModuleTransformer struct{}

CloseRootModuleTransformer is a GraphTransformer that adds a root to the graph.

func (*CloseRootModuleTransformer) Transform added in v0.13.0

func (t *CloseRootModuleTransformer) Transform(g *Graph) error

type ConcreteModuleNodeFunc added in v0.13.0

type ConcreteModuleNodeFunc func(n *nodeExpandModule) dag.Vertex

type ConcreteProviderNodeFunc added in v0.8.0

type ConcreteProviderNodeFunc func(*NodeAbstractProvider) dag.Vertex

ConcreteProviderNodeFunc is a callback type used to convert an abstract provider to a concrete one of some type.

type ConcreteResourceInstanceDeposedNodeFunc added in v0.12.0

type ConcreteResourceInstanceDeposedNodeFunc func(*NodeAbstractResourceInstance, states.DeposedKey) dag.Vertex

ConcreteResourceInstanceDeposedNodeFunc is a callback type used to convert an abstract resource instance to a concrete one of some type that has an associated deposed object key.

type ConcreteResourceInstanceNodeFunc added in v0.12.0

type ConcreteResourceInstanceNodeFunc func(*NodeAbstractResourceInstance) dag.Vertex

ConcreteResourceInstanceNodeFunc is a callback type used to convert an abstract resource instance to a concrete one of some type.

type ConcreteResourceNodeFunc added in v0.7.8

type ConcreteResourceNodeFunc func(*NodeAbstractResource) dag.Vertex

ConcreteResourceNodeFunc is a callback type used to convert an abstract resource to a concrete one of some type.

type ConfigTransformer added in v0.4.0

type ConfigTransformer struct {
	Concrete ConcreteResourceNodeFunc

	// Module is the module to add resources from.
	Config *configs.Config

	// Mode will only add resources that match the given mode
	ModeFilter bool
	Mode       addrs.ResourceMode
}

ConfigTransformer is a GraphTransformer that adds all the resources from the configuration to the graph.

The module used to configure this transformer must be the root module.

Only resources are added to the graph. Variables, outputs, and providers must be added via other transforms.

Unlike ConfigTransformerOld, this transformer creates a graph with all resources including module resources, rather than creating module nodes that are then "flattened".

func (*ConfigTransformer) Transform added in v0.4.0

func (t *ConfigTransformer) Transform(g *Graph) error

type Context

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

Context represents all the context that Terraform needs in order to perform operations on infrastructure. This structure is built using NewContext.

func NewContext

func NewContext(opts *ContextOpts) (*Context, tfdiags.Diagnostics)

NewContext creates a new Context structure.

Once a Context is created, the caller must not access or mutate any of the objects referenced (directly or indirectly) by the ContextOpts fields.

If the returned diagnostics contains errors then the resulting context is invalid and must not be used.

func (*Context) Apply

func (c *Context) Apply() (*states.State, tfdiags.Diagnostics)

Apply applies the changes represented by this context and returns the resulting state.

Even in the case an error is returned, the state may be returned and will potentially be partially updated. In addition to returning the resulting state, this context is updated with the latest state.

If the state is required after an error, the caller should call Context.State, rather than rely on the return value.

TODO: Apply and Refresh should either always return a state, or rely on the

State() method. Currently the helper/resource testing framework relies
on the absence of a returned state to determine if Destroy can be
called, so that will need to be refactored before this can be changed.

func (*Context) Config added in v0.12.0

func (c *Context) Config() *configs.Config

Config returns the configuration tree associated with this context.

func (*Context) Eval added in v0.12.0

Eval produces a scope in which expressions can be evaluated for the given module path.

This method must first evaluate any ephemeral values (input variables, local values, and output values) in the configuration. These ephemeral values are not included in the persisted state, so they must be re-computed using other values in the state before they can be properly evaluated. The updated values are retained in the main state associated with the receiving context.

This function takes no action against remote APIs but it does need access to all provider and provisioner instances in order to obtain their schemas for type checking.

The result is an evaluation scope that can be used to resolve references against the root module. If the returned diagnostics contains errors then the returned scope may be nil. If it is not nil then it may still be used to attempt expression evaluation or other analysis, but some expressions may not behave as expected.

func (*Context) Graph

func (c *Context) Graph(typ GraphType, opts *ContextGraphOpts) (*Graph, tfdiags.Diagnostics)

Graph returns the graph used for the given operation type.

The most extensive or complex graph type is GraphTypePlan.

func (*Context) Import added in v0.7.0

func (c *Context) Import(opts *ImportOpts) (*states.State, tfdiags.Diagnostics)

Import takes already-created external resources and brings them under Terraform management. Import requires the exact type, name, and ID of the resources to import.

This operation is idempotent. If the requested resource is already imported, no changes are made to the state.

Further, this operation also gracefully handles partial state. If during an import there is a failure, all previously imported resources remain imported.

func (*Context) Input added in v0.3.0

func (c *Context) Input(mode InputMode) tfdiags.Diagnostics

Input asks for input to fill unset required arguments in provider configurations.

This modifies the configuration in-place, so asking for Input twice may result in different UI output showing different current values.

func (*Context) Plan

func (c *Context) Plan() (*plans.Plan, tfdiags.Diagnostics)

Plan generates an execution plan for the given context, and returns the refreshed state.

The execution plan encapsulates the context and can be stored in order to reinstantiate a context later for Apply.

Plan also updates the diff of this context to be the diff generated by the plan, so Apply can be called after.

func (*Context) Refresh

func (c *Context) Refresh() (*states.State, tfdiags.Diagnostics)

Refresh goes through all the resources in the state and refreshes them to their latest state. This is done by executing a plan, and retaining the state while discarding the change set.

In the case of an error, there is no state returned.

func (*Context) Schemas added in v0.12.0

func (c *Context) Schemas() *Schemas

func (*Context) SetVariable added in v0.4.0

func (c *Context) SetVariable(k string, v cty.Value)

SetVariable sets a variable after a context has already been built.

func (*Context) ShadowError added in v0.7.8

func (c *Context) ShadowError() error

ShadowError returns any errors caught during a shadow operation.

A shadow operation is an operation run in parallel to a real operation that performs the same tasks using new logic on copied state. The results are compared to ensure that the new logic works the same as the old logic. The shadow never affects the real operation or return values.

The result of the shadow operation are only available through this function call after a real operation is complete.

For API consumers of Context, you can safely ignore this function completely if you have no interest in helping report experimental feature errors to Terraform maintainers. Otherwise, please call this function after every operation and report this to the user.

IMPORTANT: Shadow errors are _never_ critical: they _never_ affect the real state or result of a real operation. They are purely informational to assist in future Terraform versions being more stable. Please message this effectively to the end user.

This must be called only when no other operation is running (refresh, plan, etc.). The result can be used in parallel to any other operation running.

func (*Context) State added in v0.9.0

func (c *Context) State() *states.State

State returns a copy of the current state associated with this context.

This cannot safely be called in parallel with any other Context function.

func (*Context) Stop

func (c *Context) Stop()

Stop stops the running task.

Stop will block until the task completes.

func (*Context) Validate

func (c *Context) Validate() tfdiags.Diagnostics

Validate performs semantic validation of the configuration, and returning any warnings or errors.

Syntax and structural checks are performed by the configuration loader, and so are not repeated here.

func (*Context) Variables added in v0.4.0

func (c *Context) Variables() InputValues

Variables will return the mapping of variables that were defined for this Context. If Input was called, this mapping may be different than what was given.

type ContextGraphOpts added in v0.5.0

type ContextGraphOpts struct {
	// If true, validates the graph structure (checks for cycles).
	Validate bool

	// Legacy graphs only: won't prune the graph
	Verbose bool
}

type ContextGraphWalker added in v0.4.0

type ContextGraphWalker struct {
	NullGraphWalker

	// Configurable values
	Context            *Context
	State              *states.SyncState   // Used for safe concurrent access to state
	RefreshState       *states.SyncState   // Used for safe concurrent access to state
	Changes            *plans.ChangesSync  // Used for safe concurrent writes to changes
	InstanceExpander   *instances.Expander // Tracks our gradual expansion of module and resource instances
	Operation          walkOperation
	StopContext        context.Context
	RootVariableValues InputValues

	// This is an output. Do not set this, nor read it while a graph walk
	// is in progress.
	NonFatalDiagnostics tfdiags.Diagnostics
	// contains filtered or unexported fields
}

ContextGraphWalker is the GraphWalker implementation used with the Context struct to walk and evaluate the graph.

func (*ContextGraphWalker) EnterPath added in v0.5.0

func (*ContextGraphWalker) EvalContext added in v0.13.0

func (w *ContextGraphWalker) EvalContext() EvalContext

func (*ContextGraphWalker) Execute added in v0.14.0

type ContextMeta added in v0.9.0

type ContextMeta struct {
	Env string // Env is the state environment

	// OriginalWorkingDir is the working directory where the Terraform CLI
	// was run from, which may no longer actually be the current working
	// directory if the user included the -chdir=... option.
	//
	// If this string is empty then the original working directory is the same
	// as the current working directory.
	//
	// In most cases we should respect the user's override by ignoring this
	// path and just using the current working directory, but this is here
	// for some exceptional cases where the original working directory is
	// needed.
	OriginalWorkingDir string
}

ContextMeta is metadata about the running context. This is information that this package or structure cannot determine on its own but exposes into Terraform in various ways. This must be provided by the Context initializer.

type ContextOpts

type ContextOpts struct {
	Config      *configs.Config
	Changes     *plans.Changes
	State       *states.State
	Targets     []addrs.Targetable
	Variables   InputValues
	Meta        *ContextMeta
	Destroy     bool
	SkipRefresh bool

	Hooks        []Hook
	Parallelism  int
	Providers    map[addrs.Provider]providers.Factory
	Provisioners map[string]provisioners.Factory

	// If non-nil, will apply as additional constraints on the provider
	// plugins that will be requested from the provider resolver.
	ProviderSHA256s map[string][]byte

	// If non-nil, will be verified to ensure that provider requirements from
	// configuration can be satisfied by the set of locked dependencies.
	LockedDependencies *depsfile.Locks

	// Set of providers to exclude from the requirements check process, as they
	// are marked as in local development.
	ProvidersInDevelopment map[addrs.Provider]struct{}

	UIInput UIInput
}

ContextOpts are the user-configurable options to create a context with NewContext.

type CountBoundaryTransformer added in v0.7.8

type CountBoundaryTransformer struct {
	Config *configs.Config
}

CountBoundaryTransformer adds a node that depends on everything else so that it runs last in order to clean up the state for nodes that are on the "count boundary": "foo.0" when only one exists becomes "foo"

func (*CountBoundaryTransformer) Transform added in v0.7.8

func (t *CountBoundaryTransformer) Transform(g *Graph) error

type DataSource added in v0.7.0

type DataSource struct {
	Name string

	// SchemaAvailable is set if the provider supports the ProviderSchema,
	// ResourceTypeSchema and DataSourceSchema methods. Although it is
	// included on each resource type, it's actually a provider-wide setting
	// that's smuggled here only because that avoids a breaking change to
	// the plugin protocol.
	SchemaAvailable bool
}

DataSource is a data source that a resource provider implements.

type DestroyEdgeTransformer added in v0.7.8

type DestroyEdgeTransformer struct {
	// These are needed to properly build the graph of dependencies
	// to determine what a destroy node depends on. Any of these can be nil.
	Config *configs.Config
	State  *states.State

	// If configuration is present then Schemas is required in order to
	// obtain schema information from providers and provisioners in order
	// to properly resolve implicit dependencies.
	Schemas *Schemas
}

DestroyEdgeTransformer is a GraphTransformer that creates the proper references for destroy resources. Destroy resources are more complex in that they must be depend on the destruction of resources that in turn depend on the CREATION of the node being destroy.

That is complicated. Visually:

B_d -> A_d -> A -> B

Notice that A destroy depends on B destroy, while B create depends on A create. They're inverted. This must be done for example because often dependent resources will block parent resources from deleting. Concrete example: VPC with subnets, the VPC can't be deleted while there are still subnets.

func (*DestroyEdgeTransformer) Transform added in v0.7.8

func (t *DestroyEdgeTransformer) Transform(g *Graph) error

type DestroyPlanGraphBuilder added in v0.7.8

type DestroyPlanGraphBuilder struct {
	// Config is the configuration tree to build the plan from.
	Config *configs.Config

	// State is the current state
	State *states.State

	// Components is a factory for the plug-in components (providers and
	// provisioners) available for use.
	Components contextComponentFactory

	// Schemas is the repository of schemas we will draw from to analyse
	// the configuration.
	Schemas *Schemas

	// Targets are resources to target
	Targets []addrs.Targetable

	// Validate will do structural validation of the graph.
	Validate bool
}

DestroyPlanGraphBuilder implements GraphBuilder and is responsible for planning a pure-destroy.

Planning a pure destroy operation is simple because we can ignore most ordering configuration and simply reverse the state.

func (*DestroyPlanGraphBuilder) Build added in v0.7.8

See GraphBuilder

func (*DestroyPlanGraphBuilder) Steps added in v0.7.8

See GraphBuilder

type Diff

type Diff struct {
	// Modules contains all the modules that have a diff
	Modules []*ModuleDiff
}

Diff tracks the changes that are necessary to apply a configuration to an existing infrastructure.

func (*Diff) AddModule added in v0.3.0

func (d *Diff) AddModule(path addrs.ModuleInstance) *ModuleDiff

AddModule adds the module with the given path to the diff.

This should be the preferred method to add module diffs since it allows us to optimize lookups later as well as control sorting.

func (*Diff) DeepCopy added in v0.7.8

func (d *Diff) DeepCopy() *Diff

DeepCopy performs a deep copy of all parts of the Diff, making the resulting Diff safe to use without modifying this one.

func (*Diff) Empty

func (d *Diff) Empty() bool

Empty returns true if the diff has no changes.

func (*Diff) Equal added in v0.7.8

func (d *Diff) Equal(d2 *Diff) bool

Equal compares two diffs for exact equality.

This is different from the Same comparison that is supported which checks for operation equality taking into account computed values. Equal instead checks for exact equality.

func (*Diff) ModuleByPath added in v0.3.0

func (d *Diff) ModuleByPath(path addrs.ModuleInstance) *ModuleDiff

ModuleByPath is used to lookup the module diff for the given path. This should be the preferred lookup mechanism as it allows for future lookup optimizations.

func (*Diff) Prune added in v0.7.10

func (d *Diff) Prune()

Prune cleans out unused structures in the diff without affecting the behavior of the diff at all.

This is not safe to call concurrently. This is safe to call on a nil Diff.

func (*Diff) RootModule added in v0.3.0

func (d *Diff) RootModule() *ModuleDiff

RootModule returns the ModuleState for the root module

func (*Diff) String

func (d *Diff) String() string

type DiffAttrType

type DiffAttrType byte

DiffAttrType is an enum type that says whether a resource attribute diff is an input attribute (comes from the configuration) or an output attribute (comes as a result of applying the configuration). An example input would be "ami" for AWS and an example output would be "private_ip".

const (
	DiffAttrUnknown DiffAttrType = iota
	DiffAttrInput
	DiffAttrOutput
)

type DiffChangeType added in v0.3.0

type DiffChangeType byte

DiffChangeType is an enum with the kind of changes a diff has planned.

const (
	DiffInvalid DiffChangeType = iota
	DiffNone
	DiffCreate
	DiffUpdate
	DiffDestroy
	DiffDestroyCreate

	// DiffRefresh is only used in the UI for displaying diffs.
	// Managed resource reads never appear in plan, and when data source
	// reads appear they are represented as DiffCreate in core before
	// transforming to DiffRefresh in the UI layer.
	DiffRefresh // TODO: Actually use DiffRefresh in core too, for less confusion
)

type DiffTransformer added in v0.7.8

type DiffTransformer struct {
	Concrete ConcreteResourceInstanceNodeFunc
	State    *states.State
	Changes  *plans.Changes
}

DiffTransformer is a GraphTransformer that adds graph nodes representing each of the resource changes described in the given Changes object.

func (*DiffTransformer) Transform added in v0.7.8

func (t *DiffTransformer) Transform(g *Graph) error

type EphemeralState added in v0.3.0

type EphemeralState struct {
	// ConnInfo is used for the providers to export information which is
	// used to connect to the resource for provisioning. For example,
	// this could contain SSH or WinRM credentials.
	ConnInfo map[string]string `json:"-"`

	// Type is used to specify the resource type for this instance. This is only
	// required for import operations (as documented). If the documentation
	// doesn't state that you need to set this, then don't worry about
	// setting it.
	Type string `json:"-"`
}

EphemeralState is used for transient state that is only kept in-memory

func (*EphemeralState) DeepCopy added in v0.7.0

func (e *EphemeralState) DeepCopy() *EphemeralState

type EvalApply added in v0.4.0

type EvalApply struct {
	Addr                addrs.ResourceInstance
	Config              *configs.Resource
	State               **states.ResourceInstanceObject
	Change              **plans.ResourceInstanceChange
	ProviderAddr        addrs.AbsProviderConfig
	Provider            *providers.Interface
	ProviderMetas       map[addrs.Provider]*configs.ProviderMeta
	ProviderSchema      **ProviderSchema
	Output              **states.ResourceInstanceObject
	CreateNew           *bool
	Error               *error
	CreateBeforeDestroy bool
}

EvalApply is an EvalNode implementation that writes the diff to the full diff.

func (*EvalApply) Eval added in v0.4.0

func (n *EvalApply) Eval(ctx EvalContext) (interface{}, error)

TODO: test

type EvalApplyPost added in v0.4.0

type EvalApplyPost struct {
	Addr  addrs.ResourceInstance
	Gen   states.Generation
	State **states.ResourceInstanceObject
	Error *error
}

EvalApplyPost is an EvalNode implementation that does the post-Apply work

func (*EvalApplyPost) Eval added in v0.4.0

func (n *EvalApplyPost) Eval(ctx EvalContext) (interface{}, error)

TODO: test

type EvalApplyPre added in v0.9.0

type EvalApplyPre struct {
	Addr   addrs.ResourceInstance
	Gen    states.Generation
	State  **states.ResourceInstanceObject
	Change **plans.ResourceInstanceChange
}

EvalApplyPre is an EvalNode implementation that does the pre-Apply work

func (*EvalApplyPre) Eval added in v0.9.0

func (n *EvalApplyPre) Eval(ctx EvalContext) (interface{}, error)

TODO: test

type EvalApplyProvisioners added in v0.4.0

type EvalApplyProvisioners struct {
	Addr           addrs.ResourceInstance
	State          **states.ResourceInstanceObject
	ResourceConfig *configs.Resource
	CreateNew      *bool
	Error          *error

	// When is the type of provisioner to run at this point
	When configs.ProvisionerWhen
}

EvalApplyProvisioners is an EvalNode implementation that executes the provisioners for a resource.

TODO(mitchellh): This should probably be split up into a more fine-grained ApplyProvisioner (single) that is looped over.

func (*EvalApplyProvisioners) Eval added in v0.4.0

func (n *EvalApplyProvisioners) Eval(ctx EvalContext) (interface{}, error)

TODO: test

type EvalCheckPlannedChange added in v0.12.0

type EvalCheckPlannedChange struct {
	Addr           addrs.ResourceInstance
	ProviderAddr   addrs.AbsProviderConfig
	ProviderSchema **ProviderSchema

	// We take ResourceInstanceChange objects here just because that's what's
	// convenient to pass in from the evaltree implementation, but we really
	// only look at the "After" value of each change.
	Planned, Actual **plans.ResourceInstanceChange
}

EvalCheckPlannedChange is an EvalNode implementation that produces errors if the _actual_ expected value is not compatible with what was recorded in the plan.

Errors here are most often indicative of a bug in the provider, so our error messages will report with that in mind. It's also possible that there's a bug in Terraform's Core's own "proposed new value" code in EvalDiff.

func (*EvalCheckPlannedChange) Eval added in v0.12.0

func (n *EvalCheckPlannedChange) Eval(ctx EvalContext) (interface{}, error)

type EvalContext added in v0.4.0

type EvalContext interface {
	// Stopped returns a channel that is closed when evaluation is stopped
	// via Terraform.Context.Stop()
	Stopped() <-chan struct{}

	// Path is the current module path.
	Path() addrs.ModuleInstance

	// Hook is used to call hook methods. The callback is called for each
	// hook and should return the hook action to take and the error.
	Hook(func(Hook) (HookAction, error)) error

	// Input is the UIInput object for interacting with the UI.
	Input() UIInput

	// InitProvider initializes the provider with the given address, and returns
	// the implementation of the resource provider or an error.
	//
	// It is an error to initialize the same provider more than once. This
	// method will panic if the module instance address of the given provider
	// configuration does not match the Path() of the EvalContext.
	InitProvider(addr addrs.AbsProviderConfig) (providers.Interface, error)

	// Provider gets the provider instance with the given address (already
	// initialized) or returns nil if the provider isn't initialized.
	//
	// This method expects an _absolute_ provider configuration address, since
	// resources in one module are able to use providers from other modules.
	// InitProvider must've been called on the EvalContext of the module
	// that owns the given provider before calling this method.
	Provider(addrs.AbsProviderConfig) providers.Interface

	// ProviderSchema retrieves the schema for a particular provider, which
	// must have already been initialized with InitProvider.
	//
	// This method expects an _absolute_ provider configuration address, since
	// resources in one module are able to use providers from other modules.
	ProviderSchema(addrs.AbsProviderConfig) *ProviderSchema

	// CloseProvider closes provider connections that aren't needed anymore.
	//
	// This method will panic if the module instance address of the given
	// provider configuration does not match the Path() of the EvalContext.
	CloseProvider(addrs.AbsProviderConfig) error

	// ConfigureProvider configures the provider with the given
	// configuration. This is a separate context call because this call
	// is used to store the provider configuration for inheritance lookups
	// with ParentProviderConfig().
	//
	// This method will panic if the module instance address of the given
	// provider configuration does not match the Path() of the EvalContext.
	ConfigureProvider(addrs.AbsProviderConfig, cty.Value) tfdiags.Diagnostics

	// ProviderInput and SetProviderInput are used to configure providers
	// from user input.
	//
	// These methods will panic if the module instance address of the given
	// provider configuration does not match the Path() of the EvalContext.
	ProviderInput(addrs.AbsProviderConfig) map[string]cty.Value
	SetProviderInput(addrs.AbsProviderConfig, map[string]cty.Value)

	// InitProvisioner initializes the provisioner with the given name.
	// It is an error to initialize the same provisioner more than once.
	InitProvisioner(string) error

	// Provisioner gets the provisioner instance with the given name (already
	// initialized) or returns nil if the provisioner isn't initialized.
	Provisioner(string) provisioners.Interface

	// ProvisionerSchema retrieves the main configuration schema for a
	// particular provisioner, which must have already been initialized with
	// InitProvisioner.
	ProvisionerSchema(string) *configschema.Block

	// CloseProvisioner closes provisioner connections that aren't needed
	// anymore.
	CloseProvisioner(string) error

	// EvaluateBlock takes the given raw configuration block and associated
	// schema and evaluates it to produce a value of an object type that
	// conforms to the implied type of the schema.
	//
	// The "self" argument is optional. If given, it is the referenceable
	// address that the name "self" should behave as an alias for when
	// evaluating. Set this to nil if the "self" object should not be available.
	//
	// The "key" argument is also optional. If given, it is the instance key
	// of the current object within the multi-instance container it belongs
	// to. For example, on a resource block with "count" set this should be
	// set to a different addrs.IntKey for each instance created from that
	// block. Set this to addrs.NoKey if not appropriate.
	//
	// The returned body is an expanded version of the given body, with any
	// "dynamic" blocks replaced with zero or more static blocks. This can be
	// used to extract correct source location information about attributes of
	// the returned object value.
	EvaluateBlock(body hcl.Body, schema *configschema.Block, self addrs.Referenceable, keyData InstanceKeyEvalData) (cty.Value, hcl.Body, tfdiags.Diagnostics)

	// EvaluateExpr takes the given HCL expression and evaluates it to produce
	// a value.
	//
	// The "self" argument is optional. If given, it is the referenceable
	// address that the name "self" should behave as an alias for when
	// evaluating. Set this to nil if the "self" object should not be available.
	EvaluateExpr(expr hcl.Expression, wantType cty.Type, self addrs.Referenceable) (cty.Value, tfdiags.Diagnostics)

	// EvaluationScope returns a scope that can be used to evaluate reference
	// addresses in this context.
	EvaluationScope(self addrs.Referenceable, keyData InstanceKeyEvalData) *lang.Scope

	// SetModuleCallArguments defines values for the variables of a particular
	// child module call.
	//
	// Calling this function multiple times has merging behavior, keeping any
	// previously-set keys that are not present in the new map.
	SetModuleCallArguments(addrs.ModuleCallInstance, map[string]cty.Value)

	// GetVariableValue returns the value provided for the input variable with
	// the given address, or cty.DynamicVal if the variable hasn't been assigned
	// a value yet.
	//
	// Most callers should deal with variable values only indirectly via
	// EvaluationScope and the other expression evaluation functions, but
	// this is provided because variables tend to be evaluated outside of
	// the context of the module they belong to and so we sometimes need to
	// override the normal expression evaluation behavior.
	GetVariableValue(addr addrs.AbsInputVariableInstance) cty.Value

	// Changes returns the writer object that can be used to write new proposed
	// changes into the global changes set.
	Changes() *plans.ChangesSync

	// State returns a wrapper object that provides safe concurrent access to
	// the global state.
	State() *states.SyncState

	// RefreshState returns a wrapper object that provides safe concurrent
	// access to the state used to store the most recently refreshed resource
	// values.
	RefreshState() *states.SyncState

	// InstanceExpander returns a helper object for tracking the expansion of
	// graph nodes during the plan phase in response to "count" and "for_each"
	// arguments.
	//
	// The InstanceExpander is a global object that is shared across all of the
	// EvalContext objects for a given configuration.
	InstanceExpander() *instances.Expander

	// WithPath returns a copy of the context with the internal path set to the
	// path argument.
	WithPath(path addrs.ModuleInstance) EvalContext
}

EvalContext is the interface that is given to eval nodes to execute.

type EvalDeposeState added in v0.4.0

type EvalDeposeState struct {
	Addr addrs.ResourceInstance

	// ForceKey, if a value other than states.NotDeposed, will be used as the
	// key for the newly-created deposed object that results from this action.
	// If set to states.NotDeposed (the zero value), a new unique key will be
	// allocated.
	ForceKey states.DeposedKey

	// OutputKey, if non-nil, will be written with the deposed object key that
	// was generated for the object. This can then be passed to
	// EvalUndeposeState.Key so it knows which deposed instance to forget.
	OutputKey *states.DeposedKey
}

EvalDeposeState is an EvalNode implementation that moves the current object for the given instance to instead be a deposed object, leaving the instance with no current object. This is used at the beginning of a create-before-destroy replace action so that the create can create while preserving the old state of the to-be-destroyed object.

func (*EvalDeposeState) Eval added in v0.4.0

func (n *EvalDeposeState) Eval(ctx EvalContext) (interface{}, error)

TODO: test

type EvalDiff added in v0.4.0

type EvalDiff struct {
	Addr           addrs.ResourceInstance
	Config         *configs.Resource
	Provider       *providers.Interface
	ProviderAddr   addrs.AbsProviderConfig
	ProviderMetas  map[addrs.Provider]*configs.ProviderMeta
	ProviderSchema **ProviderSchema
	State          **states.ResourceInstanceObject
	PreviousDiff   **plans.ResourceInstanceChange

	// CreateBeforeDestroy is set if either the resource's own config sets
	// create_before_destroy explicitly or if dependencies have forced the
	// resource to be handled as create_before_destroy in order to avoid
	// a dependency cycle.
	CreateBeforeDestroy bool

	OutputChange **plans.ResourceInstanceChange
	OutputState  **states.ResourceInstanceObject

	Stub bool
}

EvalDiff is an EvalNode implementation that detects changes for a given resource instance.

func (*EvalDiff) Eval added in v0.4.0

func (n *EvalDiff) Eval(ctx EvalContext) (interface{}, error)

TODO: test

type EvalDiffDestroy added in v0.4.0

type EvalDiffDestroy struct {
	Addr         addrs.ResourceInstance
	DeposedKey   states.DeposedKey
	State        **states.ResourceInstanceObject
	ProviderAddr addrs.AbsProviderConfig

	Output      **plans.ResourceInstanceChange
	OutputState **states.ResourceInstanceObject
}

EvalDiffDestroy is an EvalNode implementation that returns a plain destroy diff.

func (*EvalDiffDestroy) Eval added in v0.4.0

func (n *EvalDiffDestroy) Eval(ctx EvalContext) (interface{}, error)

TODO: test

type EvalEarlyExitError added in v0.4.0

type EvalEarlyExitError struct{}

EvalEarlyExitError is a special error return value that can be returned by eval nodes that does an early exit.

func (EvalEarlyExitError) Error added in v0.4.0

func (EvalEarlyExitError) Error() string

type EvalGraphBuilder added in v0.12.0

type EvalGraphBuilder struct {
	// Config is the configuration tree.
	Config *configs.Config

	// State is the current state
	State *states.State

	// Components is a factory for the plug-in components (providers and
	// provisioners) available for use.
	Components contextComponentFactory

	// Schemas is the repository of schemas we will draw from to analyse
	// the configuration.
	Schemas *Schemas
}

EvalGraphBuilder implements GraphBuilder and constructs a graph suitable for evaluating in-memory values (input variables, local values, output values) in the state without any other side-effects.

This graph is used only in weird cases, such as the "terraform console" CLI command, where we need to evaluate expressions against the state without taking any other actions.

The generated graph will include nodes for providers, resources, etc just to allow indirect dependencies to be resolved, but these nodes will not take any actions themselves since we assume that their parts of the state, if any, are already complete.

Although the providers are never configured, they must still be available in order to obtain schema information used for type checking, etc.

func (*EvalGraphBuilder) Build added in v0.12.0

See GraphBuilder

func (*EvalGraphBuilder) Steps added in v0.12.0

func (b *EvalGraphBuilder) Steps() []GraphTransformer

See GraphBuilder

type EvalMaybeRestoreDeposedObject added in v0.12.0

type EvalMaybeRestoreDeposedObject struct {
	Addr addrs.ResourceInstance

	// PlannedChange might be the action we're performing that includes
	// the possiblity of restoring a deposed object. However, it might also
	// be nil. It's here only for use in error messages and must not be
	// used for business logic.
	PlannedChange **plans.ResourceInstanceChange

	// Key is a pointer to the deposed object key that should be forgotten
	// from the state, which must be non-nil.
	Key *states.DeposedKey
}

EvalMaybeRestoreDeposedObject is an EvalNode implementation that will restore a particular deposed object of the specified resource instance to be the "current" object if and only if the instance doesn't currently have a current object.

This is intended for use when the create leg of a create before destroy fails with no partial new object: if we didn't take any action, the user would be left in the unfortunate situation of having no current object and the previously-workign object now deposed. This EvalNode causes a better outcome by restoring things to how they were before the replace operation began.

The create operation may have produced a partial result even though it failed and it's important that we don't "forget" that state, so in that situation the prior object remains deposed and the partial new object remains the current object, allowing the situation to hopefully be improved in a subsequent run.

func (*EvalMaybeRestoreDeposedObject) Eval added in v0.12.0

func (n *EvalMaybeRestoreDeposedObject) Eval(ctx EvalContext) (interface{}, error)

TODO: test

type EvalMaybeTainted added in v0.12.0

type EvalMaybeTainted struct {
	Addr   addrs.ResourceInstance
	Gen    states.Generation
	Change **plans.ResourceInstanceChange
	State  **states.ResourceInstanceObject
	Error  *error
}

EvalMaybeTainted is an EvalNode that takes the planned change, new value, and possible error from an apply operation and produces a new instance object marked as tainted if it appears that a create operation has failed.

This EvalNode never returns an error, to ensure that a subsequent EvalNode can still record the possibly-tainted object in the state.

func (*EvalMaybeTainted) Eval added in v0.12.0

func (n *EvalMaybeTainted) Eval(ctx EvalContext) (interface{}, error)

type EvalReadState added in v0.4.0

type EvalReadState struct {
	// Addr is the address of the instance to read state for.
	Addr addrs.ResourceInstance

	// ProviderSchema is the schema for the provider given in Provider.
	ProviderSchema **ProviderSchema

	// Provider is the provider that will subsequently perform actions on
	// the the state object. This is used to perform any schema upgrades
	// that might be required to prepare the stored data for use.
	Provider *providers.Interface

	// Output will be written with a pointer to the retrieved object.
	Output **states.ResourceInstanceObject
}

EvalReadState is an EvalNode implementation that reads the current object for a specific instance in the state.

func (*EvalReadState) Eval added in v0.4.0

func (n *EvalReadState) Eval(ctx EvalContext) (interface{}, error)

type EvalReadStateDeposed added in v0.4.0

type EvalReadStateDeposed struct {
	// Addr is the address of the instance to read state for.
	Addr addrs.ResourceInstance

	// Key identifies which deposed object we will read.
	Key states.DeposedKey

	// ProviderSchema is the schema for the provider given in Provider.
	ProviderSchema **ProviderSchema

	// Provider is the provider that will subsequently perform actions on
	// the the state object. This is used to perform any schema upgrades
	// that might be required to prepare the stored data for use.
	Provider *providers.Interface

	// Output will be written with a pointer to the retrieved object.
	Output **states.ResourceInstanceObject
}

EvalReadStateDeposed is an EvalNode implementation that reads the deposed InstanceState for a specific resource out of the state

func (*EvalReadStateDeposed) Eval added in v0.4.0

func (n *EvalReadStateDeposed) Eval(ctx EvalContext) (interface{}, error)

type EvalReduceDiff added in v0.12.0

type EvalReduceDiff struct {
	Addr      addrs.ResourceInstance
	InChange  **plans.ResourceInstanceChange
	Destroy   bool
	OutChange **plans.ResourceInstanceChange
}

EvalReduceDiff is an EvalNode implementation that takes a planned resource instance change as might be produced by EvalDiff or EvalDiffDestroy and "simplifies" it to a single atomic action to be performed by a specific graph node.

Callers must specify whether they are a destroy node or a regular apply node. If the result is NoOp then the given change requires no action for the specific graph node calling this and so evaluation of the that graph node should exit early and take no action.

The object written to OutChange may either be identical to InChange or a new change object derived from InChange. Because of the former case, the caller must not mutate the object returned in OutChange.

func (*EvalReduceDiff) Eval added in v0.12.0

func (n *EvalReduceDiff) Eval(ctx EvalContext) (interface{}, error)

TODO: test

type EvalRefresh added in v0.4.0

type EvalRefresh struct {
	Addr           addrs.ResourceInstance
	ProviderAddr   addrs.AbsProviderConfig
	Provider       *providers.Interface
	ProviderMetas  map[addrs.Provider]*configs.ProviderMeta
	ProviderSchema **ProviderSchema
	State          **states.ResourceInstanceObject
	Output         **states.ResourceInstanceObject
}

EvalRefresh is an EvalNode implementation that does a refresh for a resource.

func (*EvalRefresh) Eval added in v0.4.0

func (n *EvalRefresh) Eval(ctx EvalContext) (interface{}, error)

TODO: test

type EvalRefreshLifecycle added in v0.13.4

type EvalRefreshLifecycle struct {
	Addr addrs.AbsResourceInstance

	Config *configs.Resource
	// Prior State
	State **states.ResourceInstanceObject
	// ForceCreateBeforeDestroy indicates a create_before_destroy resource
	// depends on this resource.
	ForceCreateBeforeDestroy bool
}

EvalRefreshLifecycle is an EvalNode implementation that updates the status of the lifecycle options stored in the state. This currently only applies to create_before_destroy.

func (*EvalRefreshLifecycle) Eval added in v0.13.4

func (n *EvalRefreshLifecycle) Eval(ctx EvalContext) (interface{}, error)

type EvalValidateCount added in v0.4.0

type EvalValidateCount struct {
	Resource *configs.Resource
}

EvalValidateCount is an EvalNode implementation that validates the count of a resource.

func (*EvalValidateCount) Eval added in v0.4.0

func (n *EvalValidateCount) Eval(ctx EvalContext) (interface{}, error)

TODO: test

type EvalValidateProvisioner added in v0.4.0

type EvalValidateProvisioner struct {
	ResourceAddr       addrs.Resource
	Provisioner        *provisioners.Interface
	Schema             **configschema.Block
	Config             *configs.Provisioner
	ResourceHasCount   bool
	ResourceHasForEach bool
}

EvalValidateProvisioner validates the configuration of a provisioner belonging to a resource. The provisioner config is expected to contain the merged connection configurations.

func (*EvalValidateProvisioner) Validate added in v0.14.0

func (n *EvalValidateProvisioner) Validate(ctx EvalContext) error

type EvalValidateResource added in v0.4.0

type EvalValidateResource struct {
	Addr           addrs.Resource
	Provider       *providers.Interface
	ProviderSchema **ProviderSchema
	Config         *configs.Resource
	ProviderMetas  map[addrs.Provider]*configs.ProviderMeta

	// IgnoreWarnings means that warnings will not be passed through. This allows
	// "just-in-time" passes of validation to continue execution through warnings.
	IgnoreWarnings bool

	// ConfigVal, if non-nil, will be updated with the value resulting from
	// evaluating the given configuration body. Since validation is performed
	// very early, this value is likely to contain lots of unknown values,
	// but its type will conform to the schema of the resource type associated
	// with the resource instance being validated.
	ConfigVal *cty.Value
}

EvalValidateResource validates the configuration of a resource.

func (*EvalValidateResource) Validate added in v0.14.0

func (n *EvalValidateResource) Validate(ctx EvalContext) error

type EvalValidateSelfRef added in v0.12.0

type EvalValidateSelfRef struct {
	Addr           addrs.Referenceable
	Config         hcl.Body
	ProviderSchema **ProviderSchema
}

EvalValidateSelfRef is an EvalNode implementation that checks to ensure that expressions within a particular referencable block do not reference that same block.

func (*EvalValidateSelfRef) Eval added in v0.12.0

func (n *EvalValidateSelfRef) Eval(ctx EvalContext) (interface{}, error)

type EvalWriteDiff added in v0.4.0

type EvalWriteDiff struct {
	Addr           addrs.ResourceInstance
	DeposedKey     states.DeposedKey
	ProviderSchema **ProviderSchema
	Change         **plans.ResourceInstanceChange
}

EvalWriteDiff is an EvalNode implementation that saves a planned change for an instance object into the set of global planned changes.

func (*EvalWriteDiff) Eval added in v0.4.0

func (n *EvalWriteDiff) Eval(ctx EvalContext) (interface{}, error)

TODO: test

type EvalWriteState added in v0.4.0

type EvalWriteState struct {
	// Addr is the address of the instance to read state for.
	Addr addrs.ResourceInstance

	// State is the object state to save.
	State **states.ResourceInstanceObject

	// ProviderSchema is the schema for the provider given in ProviderAddr.
	ProviderSchema **ProviderSchema

	// ProviderAddr is the address of the provider configuration that
	// produced the given object.
	ProviderAddr addrs.AbsProviderConfig

	// Dependencies are the inter-resource dependencies to be stored in the
	// state.
	Dependencies *[]addrs.ConfigResource
	// contains filtered or unexported fields
}

EvalWriteState is an EvalNode implementation that saves the given object as the current object for the selected resource instance.

func (*EvalWriteState) Eval added in v0.4.0

func (n *EvalWriteState) Eval(ctx EvalContext) (interface{}, error)

type EvalWriteStateDeposed added in v0.4.0

type EvalWriteStateDeposed struct {
	// Addr is the address of the instance to read state for.
	Addr addrs.ResourceInstance

	// Key indicates which deposed object to write to.
	Key states.DeposedKey

	// State is the object state to save.
	State **states.ResourceInstanceObject

	// ProviderSchema is the schema for the provider given in ProviderAddr.
	ProviderSchema **ProviderSchema

	// ProviderAddr is the address of the provider configuration that
	// produced the given object.
	ProviderAddr addrs.AbsProviderConfig
}

EvalWriteStateDeposed is an EvalNode implementation that writes an InstanceState out to the Deposed list of a resource in the state.

func (*EvalWriteStateDeposed) Eval added in v0.4.0

func (n *EvalWriteStateDeposed) Eval(ctx EvalContext) (interface{}, error)

type Evaluator added in v0.12.0

type Evaluator struct {
	// Operation defines what type of operation this evaluator is being used
	// for.
	Operation walkOperation

	// Meta is contextual metadata about the current operation.
	Meta *ContextMeta

	// Config is the root node in the configuration tree.
	Config *configs.Config

	// VariableValues is a map from variable names to their associated values,
	// within the module indicated by ModulePath. VariableValues is modified
	// concurrently, and so it must be accessed only while holding
	// VariableValuesLock.
	//
	// The first map level is string representations of addr.ModuleInstance
	// values, while the second level is variable names.
	VariableValues     map[string]map[string]cty.Value
	VariableValuesLock *sync.Mutex

	// Schemas is a repository of all of the schemas we should need to
	// evaluate expressions. This must be constructed by the caller to
	// include schemas for all of the providers, resource types, data sources
	// and provisioners used by the given configuration and state.
	//
	// This must not be mutated during evaluation.
	Schemas *Schemas

	// State is the current state, embedded in a wrapper that ensures that
	// it can be safely accessed and modified concurrently.
	State *states.SyncState

	// Changes is the set of proposed changes, embedded in a wrapper that
	// ensures they can be safely accessed and modified concurrently.
	Changes *plans.ChangesSync
}

Evaluator provides the necessary contextual data for evaluating expressions for a particular walk operation.

func (*Evaluator) Scope added in v0.12.0

func (e *Evaluator) Scope(data lang.Data, self addrs.Referenceable) *lang.Scope

Scope creates an evaluation scope for the given module path and optional resource.

If the "self" argument is nil then the "self" object is not available in evaluated expressions. Otherwise, it behaves as an alias for the given address.

type ForcedCBDTransformer added in v0.12.0

type ForcedCBDTransformer struct {
}

ForcedCBDTransformer detects when a particular CBD-able graph node has dependencies with another that has create_before_destroy set that require it to be forced on, and forces it on.

This must be used in the plan graph builder to ensure that create_before_destroy settings are properly propagated before constructing the planned changes. This requires that the plannable resource nodes implement GraphNodeDestroyerCBD.

func (*ForcedCBDTransformer) Transform added in v0.12.0

func (t *ForcedCBDTransformer) Transform(g *Graph) error

type Graph

type Graph struct {
	// Graph is the actual DAG. This is embedded so you can call the DAG
	// methods directly.
	dag.AcyclicGraph

	// Path is the path in the module tree that this Graph represents.
	Path addrs.ModuleInstance
}

Graph represents the graph that Terraform uses to represent resources and their dependencies.

func (*Graph) DirectedGraph added in v0.8.0

func (g *Graph) DirectedGraph() dag.Grapher

func (*Graph) Walk added in v0.4.0

func (g *Graph) Walk(walker GraphWalker) tfdiags.Diagnostics

Walk walks the graph with the given walker for callbacks. The graph will be walked with full parallelism, so the walker should expect to be called in concurrently.

type GraphBuilder added in v0.4.0

type GraphBuilder interface {
	// Build builds the graph for the given module path. It is up to
	// the interface implementation whether this build should expand
	// the graph or not.
	Build(addrs.ModuleInstance) (*Graph, tfdiags.Diagnostics)
}

GraphBuilder is an interface that can be implemented and used with Terraform to build the graph that Terraform walks.

func ValidateGraphBuilder added in v0.9.0

func ValidateGraphBuilder(p *PlanGraphBuilder) GraphBuilder

ValidateGraphBuilder creates the graph for the validate operation.

ValidateGraphBuilder is based on the PlanGraphBuilder. We do this so that we only have to validate what we'd normally plan anyways. The PlanGraphBuilder given will be modified so it shouldn't be used for anything else after calling this function.

type GraphNodeAttachDependencies added in v0.12.14

type GraphNodeAttachDependencies interface {
	GraphNodeConfigResource
	AttachDependencies([]addrs.ConfigResource)
}

type GraphNodeAttachProvider added in v0.7.8

type GraphNodeAttachProvider interface {
	// ProviderName with no module prefix. Example: "aws".
	ProviderAddr() addrs.AbsProviderConfig

	// Sets the configuration
	AttachProvider(*configs.Provider)
}

GraphNodeAttachProvider is an interface that must be implemented by nodes that want provider configurations attached.

type GraphNodeAttachProviderConfigSchema added in v0.12.0

type GraphNodeAttachProviderConfigSchema interface {
	GraphNodeProvider

	AttachProviderConfigSchema(*configschema.Block)
}

GraphNodeAttachProviderConfigSchema is an interface implemented by node types that need a provider configuration schema attached.

type GraphNodeAttachProviderMetaConfigs added in v0.13.0

type GraphNodeAttachProviderMetaConfigs interface {
	GraphNodeConfigResource

	// Sets the configuration
	AttachProviderMetaConfigs(map[addrs.Provider]*configs.ProviderMeta)
}

GraphNodeAttachProviderMetaConfigs is an interface that must be implemented by nodes that want provider meta configurations attached.

type GraphNodeAttachProvisionerSchema added in v0.12.0

type GraphNodeAttachProvisionerSchema interface {
	ProvisionedBy() []string

	// SetProvisionerSchema is called during transform for each provisioner
	// type returned from ProvisionedBy, providing the configuration schema
	// for each provisioner in turn. The implementer should save these for
	// later use in evaluating provisioner configuration blocks.
	AttachProvisionerSchema(name string, schema *configschema.Block)
}

GraphNodeAttachProvisionerSchema is an interface implemented by node types that need one or more provisioner schemas attached.

type GraphNodeAttachResourceConfig added in v0.7.8

type GraphNodeAttachResourceConfig interface {
	GraphNodeConfigResource

	// Sets the configuration
	AttachResourceConfig(*configs.Resource)
}

GraphNodeAttachResourceConfig is an interface that must be implemented by nodes that want resource configurations attached.

type GraphNodeAttachResourceSchema added in v0.12.0

type GraphNodeAttachResourceSchema interface {
	GraphNodeConfigResource
	GraphNodeProviderConsumer

	AttachResourceSchema(schema *configschema.Block, version uint64)
}

GraphNodeAttachResourceSchema is an interface implemented by node types that need a resource schema attached.

type GraphNodeAttachResourceState added in v0.7.8

type GraphNodeAttachResourceState interface {
	GraphNodeResourceInstance

	// Sets the state
	AttachResourceState(*states.Resource)
}

GraphNodeAttachResourceState is an interface that can be implemented to request that a ResourceState is attached to the node.

Due to a historical naming inconsistency, the type ResourceState actually represents the state for a particular _instance_, while InstanceState represents the values for that instance during a particular phase (e.g. primary vs. deposed). Consequently, GraphNodeAttachResourceState is supported only for nodes that represent resource instances, even though the name might suggest it is for containing resources.

type GraphNodeCloseProvider added in v0.6.0

type GraphNodeCloseProvider interface {
	GraphNodeModulePath
	CloseProviderAddr() addrs.AbsProviderConfig
}

GraphNodeCloseProvider is an interface that nodes that can be a close provider must implement. The CloseProviderName returned is the name of the provider they satisfy.

type GraphNodeCloseProvisioner added in v0.6.0

type GraphNodeCloseProvisioner interface {
	CloseProvisionerName() string
}

GraphNodeCloseProvisioner is an interface that nodes that can be a close provisioner must implement. The CloseProvisionerName returned is the name of the provisioner they satisfy.

type GraphNodeConfigResource added in v0.4.0

type GraphNodeConfigResource interface {
	ResourceAddr() addrs.ConfigResource
}

GraphNodeConfigResource is implemented by any nodes that represent a resource. The type of operation cannot be assumed, only that this node represents the given resource.

type GraphNodeCreator added in v0.7.8

type GraphNodeCreator interface {
	// CreateAddr is the address of the resource being created or updated
	CreateAddr() *addrs.AbsResourceInstance
}

GraphNodeCreator must be implemented by nodes that create OR update resources.

type GraphNodeDeposedResourceInstanceObject added in v0.12.0

type GraphNodeDeposedResourceInstanceObject interface {
	DeposedInstanceObjectKey() states.DeposedKey
}

type GraphNodeDeposer added in v0.12.0

type GraphNodeDeposer interface {
	// SetPreallocatedDeposedKey will be called during graph construction
	// if a particular node must use a pre-allocated deposed key if/when it
	// "deposes" the current object of its associated resource instance.
	SetPreallocatedDeposedKey(key states.DeposedKey)
}

GraphNodeDeposer is an optional interface implemented by graph nodes that might create a single new deposed object for a specific associated resource instance, allowing a caller to optionally pre-allocate a DeposedKey for it.

type GraphNodeDestroyer added in v0.7.8

type GraphNodeDestroyer interface {
	dag.Vertex

	// DestroyAddr is the address of the resource that is being
	// destroyed by this node. If this returns nil, then this node
	// is not destroying anything.
	DestroyAddr() *addrs.AbsResourceInstance
}

GraphNodeDestroyer must be implemented by nodes that destroy resources.

type GraphNodeDestroyerCBD added in v0.7.8

type GraphNodeDestroyerCBD interface {
	// CreateBeforeDestroy returns true if this node represents a node
	// that is doing a CBD.
	CreateBeforeDestroy() bool

	// ModifyCreateBeforeDestroy is called when the CBD state of a node
	// is changed dynamically. This can return an error if this isn't
	// allowed.
	ModifyCreateBeforeDestroy(bool) error
}

GraphNodeDestroyerCBD must be implemented by nodes that might be create-before-destroy destroyers, or might plan a create-before-destroy action.

type GraphNodeDynamicExpandable added in v0.4.0

type GraphNodeDynamicExpandable interface {
	DynamicExpand(EvalContext) (*Graph, error)
}

GraphNodeDynamicExpandable is an interface that nodes can implement to signal that they can be expanded at eval-time (hence dynamic). These nodes are given the eval context and are expected to return a new subgraph.

type GraphNodeExecutable added in v0.14.0

type GraphNodeExecutable interface {
	Execute(EvalContext, walkOperation) error
}

GraphNodeExecutable is the interface that graph nodes must implement to enable execution. This is an alternative to GraphNodeEvalable, which is in the process of being removed. A given graph node should _not_ implement both GraphNodeExecutable and GraphNodeEvalable.

type GraphNodeModuleInstance added in v0.13.0

type GraphNodeModuleInstance interface {
	Path() addrs.ModuleInstance
}

GraphNodeModuleInstance says that a node is part of a graph with a different path, and the context should be adjusted accordingly.

type GraphNodeModulePath added in v0.13.0

type GraphNodeModulePath interface {
	ModulePath() addrs.Module
}

GraphNodeModulePath is implemented by all referenceable nodes, to indicate their configuration path in unexpanded modules.

type GraphNodeProvider added in v0.4.0

type GraphNodeProvider interface {
	GraphNodeModulePath
	ProviderAddr() addrs.AbsProviderConfig
	Name() string
}

GraphNodeProvider is an interface that nodes that can be a provider must implement.

ProviderAddr returns the address of the provider configuration this satisfies, which is relative to the path returned by method Path().

Name returns the full name of the provider in the config.

type GraphNodeProviderConsumer added in v0.4.0

type GraphNodeProviderConsumer interface {
	GraphNodeModulePath
	// ProvidedBy returns the address of the provider configuration the node
	// refers to, if available. The following value types may be returned:
	//
	// * addrs.LocalProviderConfig: the provider was set in the resource config
	// * addrs.AbsProviderConfig + exact true: the provider configuration was
	//   taken from the instance state.
	// * addrs.AbsProviderConfig + exact false: no config or state; the returned
	//   value is a default provider configuration address for the resource's
	//   Provider
	ProvidedBy() (addr addrs.ProviderConfig, exact bool)

	// Provider() returns the Provider FQN for the node.
	Provider() (provider addrs.Provider)

	// Set the resolved provider address for this resource.
	SetProvider(addrs.AbsProviderConfig)
}

GraphNodeProviderConsumer is an interface that nodes that require a provider must implement. ProvidedBy must return the address of the provider to use, which will be resolved to a configuration either in the same module or in an ancestor module, with the resulting absolute address passed to SetProvider.

type GraphNodeProvisioner added in v0.4.0

type GraphNodeProvisioner interface {
	ProvisionerName() string
}

GraphNodeProvisioner is an interface that nodes that can be a provisioner must implement. The ProvisionerName returned is the name of the provisioner they satisfy.

type GraphNodeProvisionerConsumer added in v0.4.0

type GraphNodeProvisionerConsumer interface {
	ProvisionedBy() []string
}

GraphNodeProvisionerConsumer is an interface that nodes that require a provisioner must implement. ProvisionedBy must return the names of the provisioners to use.

type GraphNodeReferenceOutside added in v0.12.0

type GraphNodeReferenceOutside interface {
	// ReferenceOutside returns a path in which any references from this node
	// are resolved.
	ReferenceOutside() (selfPath, referencePath addrs.Module)
}

GraphNodeReferenceOutside is an interface that can optionally be implemented. A node that implements it can specify that its own referenceable addresses and/or the addresses it references are in a different module than the node itself.

Any referenceable addresses returned by ReferenceableAddrs are interpreted relative to the returned selfPath.

Any references returned by References are interpreted relative to the returned referencePath.

It is valid but not required for either of these paths to match what is returned by method Path, though if both match the main Path then there is no reason to implement this method.

The primary use-case for this is the nodes representing module input variables, since their expressions are resolved in terms of their calling module, but they are still referenced from their own module.

type GraphNodeReferenceable added in v0.7.8

type GraphNodeReferenceable interface {
	GraphNodeModulePath

	// ReferenceableAddrs returns a list of addresses through which this can be
	// referenced.
	ReferenceableAddrs() []addrs.Referenceable
}

GraphNodeReferenceable must be implemented by any node that represents a Terraform thing that can be referenced (resource, module, etc.).

Even if the thing has no name, this should return an empty list. By implementing this and returning a non-nil result, you say that this CAN be referenced and other methods of referencing may still be possible (such as by path!)

type GraphNodeReferencer added in v0.7.8

type GraphNodeReferencer interface {
	GraphNodeModulePath

	// References returns a list of references made by this node, which
	// include both a referenced address and source location information for
	// the reference.
	References() []*addrs.Reference
}

GraphNodeReferencer must be implemented by nodes that reference other Terraform items and therefore depend on them.

type GraphNodeResourceInstance added in v0.12.0

type GraphNodeResourceInstance interface {
	ResourceInstanceAddr() addrs.AbsResourceInstance

	// StateDependencies returns any inter-resource dependencies that are
	// stored in the state.
	StateDependencies() []addrs.ConfigResource
}

GraphNodeResourceInstance is implemented by any nodes that represent a resource instance. A single resource may have multiple instances if, for example, the "count" or "for_each" argument is used for it in configuration.

type GraphNodeTargetable added in v0.4.0

type GraphNodeTargetable interface {
	SetTargets([]addrs.Targetable)
}

GraphNodeTargetable is an interface for graph nodes to implement when they need to be told about incoming targets. This is useful for nodes that need to respect targets as they dynamically expand. Note that the list of targets provided will contain every target provided, and each implementing graph node must filter this list to targets considered relevant.

type GraphTransformer added in v0.4.0

type GraphTransformer interface {
	Transform(*Graph) error
}

GraphTransformer is the interface that transformers implement. This interface is only for transforms that need entire graph visibility.

func GraphTransformIf added in v0.7.8

func GraphTransformIf(f func() bool, then GraphTransformer) GraphTransformer

GraphTransformIf is a helper function that conditionally returns a GraphTransformer given. This is useful for calling inline a sequence of transforms without having to split it up into multiple append() calls.

func GraphTransformMulti added in v0.7.8

func GraphTransformMulti(ts ...GraphTransformer) GraphTransformer

GraphTransformMulti combines multiple graph transformers into a single GraphTransformer that runs all the individual graph transformers.

func TransformProviders added in v0.11.0

func TransformProviders(providers []string, concrete ConcreteProviderNodeFunc, config *configs.Config) GraphTransformer

type GraphType added in v0.8.0

type GraphType byte

GraphType is an enum of the type of graph to create with a Context. The values of the constants may change so they shouldn't be depended on; always use the constant name.

const (
	GraphTypeInvalid GraphType = iota
	GraphTypePlan
	GraphTypePlanDestroy
	GraphTypeApply
	GraphTypeValidate
	GraphTypeEval // only visits in-memory elements such as variables, locals, and outputs.
)

func (GraphType) String added in v0.8.0

func (i GraphType) String() string

type GraphVertexTransformer added in v0.4.0

type GraphVertexTransformer interface {
	Transform(dag.Vertex) (dag.Vertex, error)
}

GraphVertexTransformer is an interface that transforms a single Vertex within with graph. This is a specialization of GraphTransformer that makes it easy to do vertex replacement.

The GraphTransformer that runs through the GraphVertexTransformers is VertexTransformer.

type GraphWalker added in v0.4.0

type GraphWalker interface {
	EvalContext() EvalContext
	EnterPath(addrs.ModuleInstance) EvalContext
	ExitPath(addrs.ModuleInstance)
	Execute(EvalContext, GraphNodeExecutable) tfdiags.Diagnostics
}

GraphWalker is an interface that can be implemented that when used with Graph.Walk will invoke the given callbacks under certain events.

type Hook

type Hook interface {
	// PreApply and PostApply are called before and after an action for a
	// single instance is applied. The error argument in PostApply is the
	// error, if any, that was returned from the provider Apply call itself.
	PreApply(addr addrs.AbsResourceInstance, gen states.Generation, action plans.Action, priorState, plannedNewState cty.Value) (HookAction, error)
	PostApply(addr addrs.AbsResourceInstance, gen states.Generation, newState cty.Value, err error) (HookAction, error)

	// PreDiff and PostDiff are called before and after a provider is given
	// the opportunity to customize the proposed new state to produce the
	// planned new state.
	PreDiff(addr addrs.AbsResourceInstance, gen states.Generation, priorState, proposedNewState cty.Value) (HookAction, error)
	PostDiff(addr addrs.AbsResourceInstance, gen states.Generation, action plans.Action, priorState, plannedNewState cty.Value) (HookAction, error)

	// The provisioning hooks signal both the overall start end end of
	// provisioning for a particular instance and of each of the individual
	// configured provisioners for each instance. The sequence of these
	// for a given instance might look something like this:
	//
	//          PreProvisionInstance(aws_instance.foo[1], ...)
	//      PreProvisionInstanceStep(aws_instance.foo[1], "file")
	//     PostProvisionInstanceStep(aws_instance.foo[1], "file", nil)
	//      PreProvisionInstanceStep(aws_instance.foo[1], "remote-exec")
	//               ProvisionOutput(aws_instance.foo[1], "remote-exec", "Installing foo...")
	//               ProvisionOutput(aws_instance.foo[1], "remote-exec", "Configuring bar...")
	//     PostProvisionInstanceStep(aws_instance.foo[1], "remote-exec", nil)
	//         PostProvisionInstance(aws_instance.foo[1], ...)
	//
	// ProvisionOutput is called with output sent back by the provisioners.
	// This will be called multiple times as output comes in, with each call
	// representing one line of output. It cannot control whether the
	// provisioner continues running.
	PreProvisionInstance(addr addrs.AbsResourceInstance, state cty.Value) (HookAction, error)
	PostProvisionInstance(addr addrs.AbsResourceInstance, state cty.Value) (HookAction, error)
	PreProvisionInstanceStep(addr addrs.AbsResourceInstance, typeName string) (HookAction, error)
	PostProvisionInstanceStep(addr addrs.AbsResourceInstance, typeName string, err error) (HookAction, error)
	ProvisionOutput(addr addrs.AbsResourceInstance, typeName string, line string)

	// PreRefresh and PostRefresh are called before and after a single
	// resource state is refreshed, respectively.
	PreRefresh(addr addrs.AbsResourceInstance, gen states.Generation, priorState cty.Value) (HookAction, error)
	PostRefresh(addr addrs.AbsResourceInstance, gen states.Generation, priorState cty.Value, newState cty.Value) (HookAction, error)

	// PreImportState and PostImportState are called before and after
	// (respectively) each state import operation for a given resource address.
	PreImportState(addr addrs.AbsResourceInstance, importID string) (HookAction, error)
	PostImportState(addr addrs.AbsResourceInstance, imported []providers.ImportedResource) (HookAction, error)

	// PostStateUpdate is called each time the state is updated. It receives
	// a deep copy of the state, which it may therefore access freely without
	// any need for locks to protect from concurrent writes from the caller.
	PostStateUpdate(new *states.State) (HookAction, error)
}

Hook is the interface that must be implemented to hook into various parts of Terraform, allowing you to inspect or change behavior at runtime.

There are MANY hook points into Terraform. If you only want to implement some hook points, but not all (which is the likely case), then embed the NilHook into your struct, which implements all of the interface but does nothing. Then, override only the functions you want to implement.

type HookAction

type HookAction byte

HookAction is an enum of actions that can be taken as a result of a hook callback. This allows you to modify the behavior of Terraform at runtime.

const (
	// HookActionContinue continues with processing as usual.
	HookActionContinue HookAction = iota

	// HookActionHalt halts immediately: no more hooks are processed
	// and the action that Terraform was about to take is cancelled.
	HookActionHalt
)

type ImportGraphBuilder added in v0.7.0

type ImportGraphBuilder struct {
	// ImportTargets are the list of resources to import.
	ImportTargets []*ImportTarget

	// Module is a configuration to build the graph from. See ImportOpts.Config.
	Config *configs.Config

	// Components is the factory for our available plugin components.
	Components contextComponentFactory

	// Schemas is the repository of schemas we will draw from to analyse
	// the configuration.
	Schemas *Schemas
}

ImportGraphBuilder implements GraphBuilder and is responsible for building a graph for importing resources into Terraform. This is a much, much simpler graph than a normal configuration graph.

func (*ImportGraphBuilder) Build added in v0.7.0

Build builds the graph according to the steps returned by Steps.

func (*ImportGraphBuilder) Steps added in v0.7.0

func (b *ImportGraphBuilder) Steps() []GraphTransformer

Steps returns the ordered list of GraphTransformers that must be executed to build a complete graph.

type ImportOpts added in v0.7.0

type ImportOpts struct {
	// Targets are the targets to import
	Targets []*ImportTarget
}

ImportOpts are used as the configuration for Import.

type ImportStateTransformer added in v0.7.0

type ImportStateTransformer struct {
	Targets []*ImportTarget
	Config  *configs.Config
}

ImportStateTransformer is a GraphTransformer that adds nodes to the graph to represent the imports we want to do for resources.

func (*ImportStateTransformer) Transform added in v0.7.0

func (t *ImportStateTransformer) Transform(g *Graph) error

type ImportTarget added in v0.7.0

type ImportTarget struct {
	// Addr is the address for the resource instance that the new object should
	// be imported into.
	Addr addrs.AbsResourceInstance

	// ID is the ID of the resource to import. This is resource-specific.
	ID string

	// ProviderAddr is the address of the provider that should handle the import.
	ProviderAddr addrs.AbsProviderConfig
}

ImportTarget is a single resource to import.

type InputMode added in v0.3.0

type InputMode byte

InputMode defines what sort of input will be asked for when Input is called on Context.

const (
	// InputModeProvider asks for provider variables
	InputModeProvider InputMode = 1 << iota

	// InputModeStd is the standard operating mode and asks for both variables
	// and providers.
	InputModeStd = InputModeProvider
)

type InputOpts added in v0.3.0

type InputOpts struct {
	// Id is a unique ID for the question being asked that might be
	// used for logging or to look up a prior answered question.
	Id string

	// Query is a human-friendly question for inputting this value.
	Query string

	// Description is a description about what this option is. Be wary
	// that this will probably be in a terminal so split lines as you see
	// necessary.
	Description string

	// Default will be the value returned if no data is entered.
	Default string

	// Secret should be true if we are asking for sensitive input.
	// If attached to a TTY, Terraform will disable echo.
	Secret bool
}

InputOpts are options for asking for input.

type InputValue added in v0.12.0

type InputValue struct {
	Value      cty.Value
	SourceType ValueSourceType

	// SourceRange provides source location information for values whose
	// SourceType is either ValueFromConfig or ValueFromFile. It is not
	// populated for other source types, and so should not be used.
	SourceRange tfdiags.SourceRange
}

InputValue represents a value for a variable in the root module, provided as part of the definition of an operation.

func (*InputValue) GoString added in v0.12.0

func (v *InputValue) GoString() string

type InputValues added in v0.12.0

type InputValues map[string]*InputValue

InputValues is a map of InputValue instances.

func DefaultVariableValues added in v0.12.0

func DefaultVariableValues(configs map[string]*configs.Variable) InputValues

DefaultVariableValues returns an InputValues map representing the default values specified for variables in the given configuration map.

func InputValuesFromCaller added in v0.12.0

func InputValuesFromCaller(vals map[string]cty.Value) InputValues

InputValuesFromCaller turns the given map of naked values into an InputValues that attributes each value to "a caller", using the source type ValueFromCaller. This is primarily useful for testing purposes.

This should not be used as a general way to convert map[string]cty.Value into InputValues, since in most real cases we want to set a suitable other SourceType and possibly SourceRange value.

func (InputValues) HasValues added in v0.12.0

func (vv InputValues) HasValues(vals map[string]cty.Value) bool

HasValues returns true if the reciever has the same values as in the given map, disregarding the source types and source ranges.

Values are compared using the cty "RawEquals" method, which means that unknown values can be considered equal to one another if they are of the same type.

func (InputValues) Identical added in v0.12.0

func (vv InputValues) Identical(other InputValues) bool

Identical returns true if the given InputValues has the same values, source types, and source ranges as the receiver.

Values are compared using the cty "RawEquals" method, which means that unknown values can be considered equal to one another if they are of the same type.

This method is primarily for testing. For most practical purposes, it's better to use SameValues or HasValues.

func (InputValues) JustValues added in v0.12.0

func (vv InputValues) JustValues() map[string]cty.Value

JustValues returns a map that just includes the values, discarding the source information.

func (InputValues) Override added in v0.12.0

func (vv InputValues) Override(others ...InputValues) InputValues

Override merges the given value maps with the receiver, overriding any conflicting keys so that the latest definition wins.

func (InputValues) SameValues added in v0.12.0

func (vv InputValues) SameValues(other InputValues) bool

SameValues returns true if the given InputValues has the same values as the receiever, disregarding the source types and source ranges.

Values are compared using the cty "RawEquals" method, which means that unknown values can be considered equal to one another if they are of the same type.

type InstanceDiff added in v0.3.0

type InstanceDiff struct {
	Attributes     map[string]*ResourceAttrDiff
	Destroy        bool
	DestroyDeposed bool
	DestroyTainted bool

	// Meta is a simple K/V map that is stored in a diff and persisted to
	// plans but otherwise is completely ignored by Terraform core. It is
	// meant to be used for additional data a resource may want to pass through.
	// The value here must only contain Go primitives and collections.
	Meta map[string]interface{}
	// contains filtered or unexported fields
}

InstanceDiff is the diff of a resource from some state to another.

func NewInstanceDiff added in v0.7.0

func NewInstanceDiff() *InstanceDiff

func (*InstanceDiff) Apply added in v0.12.0

func (d *InstanceDiff) Apply(attrs map[string]string, schema *configschema.Block) (map[string]string, error)

Apply applies the diff to the provided flatmapped attributes, returning the new instance attributes.

This method is intended for shimming old subsystems that still use this legacy diff type to work with the new-style types.

func (*InstanceDiff) ApplyToValue added in v0.12.0

func (d *InstanceDiff) ApplyToValue(base cty.Value, schema *configschema.Block) (cty.Value, error)

ApplyToValue merges the receiver into the given base value, returning a new value that incorporates the planned changes. The given value must conform to the given schema, or this method will panic.

This method is intended for shimming old subsystems that still use this legacy diff type to work with the new-style types.

func (*InstanceDiff) ChangeType added in v0.3.0

func (d *InstanceDiff) ChangeType() DiffChangeType

ChangeType returns the DiffChangeType represented by the diff for this single instance.

func (*InstanceDiff) Copy added in v0.7.9

func (d *InstanceDiff) Copy() (*InstanceDiff, error)

func (*InstanceDiff) CopyAttributes added in v0.7.0

func (d *InstanceDiff) CopyAttributes() map[string]*ResourceAttrDiff

Safely copies the Attributes map

func (*InstanceDiff) DeepCopy added in v0.7.8

func (d *InstanceDiff) DeepCopy() *InstanceDiff

DeepCopy performs a deep copy of all parts of the InstanceDiff

func (*InstanceDiff) DelAttribute added in v0.7.0

func (d *InstanceDiff) DelAttribute(key string)

func (*InstanceDiff) Empty added in v0.3.0

func (d *InstanceDiff) Empty() bool

Empty returns true if this diff encapsulates no changes.

func (*InstanceDiff) Equal added in v0.7.8

func (d *InstanceDiff) Equal(d2 *InstanceDiff) bool

Equal compares two diffs for exact equality.

This is different from the Same comparison that is supported which checks for operation equality taking into account computed values. Equal instead checks for exact equality.

func (*InstanceDiff) GetAttribute added in v0.7.0

func (d *InstanceDiff) GetAttribute(key string) (*ResourceAttrDiff, bool)

func (*InstanceDiff) GetAttributesLen added in v0.7.0

func (d *InstanceDiff) GetAttributesLen() int

func (*InstanceDiff) GetDestroy added in v0.7.0

func (d *InstanceDiff) GetDestroy() bool

func (*InstanceDiff) GetDestroyDeposed added in v0.8.0

func (d *InstanceDiff) GetDestroyDeposed() bool

func (*InstanceDiff) GetDestroyTainted added in v0.7.0

func (d *InstanceDiff) GetDestroyTainted() bool

func (*InstanceDiff) GoString added in v0.4.0

func (d *InstanceDiff) GoString() string

func (*InstanceDiff) Lock added in v0.7.9

func (d *InstanceDiff) Lock()

func (*InstanceDiff) RequiresNew added in v0.3.0

func (d *InstanceDiff) RequiresNew() bool

RequiresNew returns true if the diff requires the creation of a new resource (implying the destruction of the old).

func (*InstanceDiff) Same added in v0.3.0

func (d *InstanceDiff) Same(d2 *InstanceDiff) (bool, string)

Same checks whether or not two InstanceDiff's are the "same". When we say "same", it is not necessarily exactly equal. Instead, it is just checking that the same attributes are changing, a destroy isn't suddenly happening, etc.

func (*InstanceDiff) SetAttribute added in v0.7.0

func (d *InstanceDiff) SetAttribute(key string, attr *ResourceAttrDiff)

func (*InstanceDiff) SetDestroy added in v0.7.0

func (d *InstanceDiff) SetDestroy(b bool)

func (*InstanceDiff) SetDestroyDeposed added in v0.8.0

func (d *InstanceDiff) SetDestroyDeposed(b bool)

func (*InstanceDiff) SetTainted added in v0.7.0

func (d *InstanceDiff) SetTainted(b bool)

These methods are properly locked, for use outside other InstanceDiff methods but everywhere else within the terraform package. TODO refactor the locking scheme

func (*InstanceDiff) Unlock added in v0.7.9

func (d *InstanceDiff) Unlock()

type InstanceInfo added in v0.3.0

type InstanceInfo struct {
	// Id is a unique name to represent this instance. This is not related
	// to InstanceState.ID in any way.
	Id string

	// ModulePath is the complete path of the module containing this
	// instance.
	ModulePath []string

	// Type is the resource type of this instance
	Type string
	// contains filtered or unexported fields
}

InstanceInfo is used to hold information about the instance and/or resource being modified.

func NewInstanceInfo added in v0.12.0

func NewInstanceInfo(addr addrs.AbsResourceInstance) *InstanceInfo

NewInstanceInfo constructs an InstanceInfo from an addrs.AbsResourceInstance.

InstanceInfo is a legacy type, and uses of it should be gradually replaced by direct use of addrs.AbsResource or addrs.AbsResourceInstance as appropriate.

The legacy InstanceInfo type cannot represent module instances with instance keys, so this function will panic if given such a path. Uses of this type should all be removed or replaced before implementing "count" and "for_each" arguments on modules in order to avoid such panics.

This legacy type also cannot represent resource instances with string instance keys. It will panic if the given key is not either NoKey or an IntKey.

func (*InstanceInfo) ResourceAddress added in v0.10.4

func (i *InstanceInfo) ResourceAddress() *ResourceAddress

ResourceAddress returns the address of the resource that the receiver is describing.

type InstanceKeyEvalData added in v0.12.0

type InstanceKeyEvalData = instances.RepetitionData

InstanceKeyEvalData is the old name for instances.RepetitionData, aliased here for compatibility. In new code, use instances.RepetitionData instead.

func EvalDataForInstanceKey added in v0.12.0

func EvalDataForInstanceKey(key addrs.InstanceKey, forEachMap map[string]cty.Value) InstanceKeyEvalData

EvalDataForInstanceKey constructs a suitable InstanceKeyEvalData for evaluating in a context that has the given instance key.

The forEachMap argument can be nil when preparing for evaluation in a context where each.value is prohibited, such as a destroy-time provisioner. In that case, the returned EachValue will always be cty.NilVal.

type InstanceState added in v0.3.0

type InstanceState struct {
	// A unique ID for this resource. This is opaque to Terraform
	// and is only meant as a lookup mechanism for the providers.
	ID string `json:"id"`

	// Attributes are basic information about the resource. Any keys here
	// are accessible in variable format within Terraform configurations:
	// ${resourcetype.name.attribute}.
	Attributes map[string]string `json:"attributes"`

	// Ephemeral is used to store any state associated with this instance
	// that is necessary for the Terraform run to complete, but is not
	// persisted to a state file.
	Ephemeral EphemeralState `json:"-"`

	// Meta is a simple K/V map that is persisted to the State but otherwise
	// ignored by Terraform core. It's meant to be used for accounting by
	// external client code. The value here must only contain Go primitives
	// and collections.
	Meta map[string]interface{} `json:"meta"`

	ProviderMeta cty.Value

	// Tainted is used to mark a resource for recreation.
	Tainted bool `json:"tainted"`
	// contains filtered or unexported fields
}

InstanceState is used to track the unique state information belonging to a given instance.

func NewInstanceStateShimmedFromValue added in v0.12.0

func NewInstanceStateShimmedFromValue(state cty.Value, schemaVersion int) *InstanceState

NewInstanceStateShimmedFromValue is a shim method to lower a new-style object value representing the attributes of an instance object into the legacy InstanceState representation.

This is for shimming to old components only and should not be used in new code.

func (*InstanceState) AttrsAsObjectValue added in v0.12.0

func (s *InstanceState) AttrsAsObjectValue(ty cty.Type) (cty.Value, error)

AttrsAsObjectValue shims from the legacy InstanceState representation to a new-style cty object value representation of the state attributes, using the given type for guidance.

The given type must be the implied type of the schema of the resource type of the object whose state is being converted, or the result is undefined.

This is for shimming from old components only and should not be used in new code.

func (*InstanceState) DeepCopy added in v0.7.0

func (s *InstanceState) DeepCopy() *InstanceState

func (*InstanceState) Empty added in v0.4.0

func (s *InstanceState) Empty() bool

func (*InstanceState) Equal added in v0.4.0

func (s *InstanceState) Equal(other *InstanceState) bool

func (*InstanceState) Lock added in v0.7.3

func (s *InstanceState) Lock()

func (*InstanceState) MergeDiff added in v0.3.0

func (s *InstanceState) MergeDiff(d *InstanceDiff) *InstanceState

MergeDiff takes a ResourceDiff and merges the attributes into this resource state in order to generate a new state. This new state can be used to provide updated attribute lookups for variable interpolation.

If the diff attribute requires computing the value, and hence won't be available until apply, the value is replaced with the computeID.

func (*InstanceState) Set added in v0.7.3

func (s *InstanceState) Set(from *InstanceState)

Copy all the Fields from another InstanceState

func (*InstanceState) String added in v0.3.0

func (s *InstanceState) String() string

func (*InstanceState) Unlock added in v0.7.3

func (s *InstanceState) Unlock()

type InstanceType added in v0.4.0

type InstanceType int

InstanceType is an enum of the various types of instances store in the State

const (
	TypeInvalid InstanceType = iota
	TypePrimary
	TypeTainted
	TypeDeposed
)

func ParseInstanceType added in v0.4.0

func ParseInstanceType(s string) (InstanceType, error)

func (InstanceType) String added in v0.4.0

func (i InstanceType) String() string

type LocalTransformer added in v0.10.3

type LocalTransformer struct {
	Config *configs.Config
}

LocalTransformer is a GraphTransformer that adds all the local values from the configuration to the graph.

func (*LocalTransformer) Transform added in v0.10.3

func (t *LocalTransformer) Transform(g *Graph) error

type MissingProviderTransformer added in v0.4.0

type MissingProviderTransformer struct {
	// Providers is the list of providers we support.
	Providers []string

	// MissingProviderTransformer needs the config to rule out _implied_ default providers
	Config *configs.Config

	// Concrete, if set, overrides how the providers are made.
	Concrete ConcreteProviderNodeFunc
}

MissingProviderTransformer is a GraphTransformer that adds to the graph a node for each default provider configuration that is referenced by another node but not already present in the graph.

These "default" nodes are always added to the root module, regardless of where they are requested. This is important because our inheritance resolution behavior in ProviderTransformer will then treat these as a last-ditch fallback after walking up the tree, rather than preferring them as it would if they were placed in the same module as the requester.

This transformer may create extra nodes that are not needed in practice, due to overriding provider configurations in child modules. PruneProviderTransformer can then remove these once ProviderTransformer has resolved all of the inheritence, etc.

func (*MissingProviderTransformer) Transform added in v0.4.0

func (t *MissingProviderTransformer) Transform(g *Graph) error

type MissingProvisionerTransformer added in v0.4.0

type MissingProvisionerTransformer struct {
	// Provisioners is the list of provisioners we support.
	Provisioners []string
}

MissingProvisionerTransformer is a GraphTransformer that adds nodes for missing provisioners into the graph.

func (*MissingProvisionerTransformer) Transform added in v0.4.0

func (t *MissingProvisionerTransformer) Transform(g *Graph) error

type MockEvalContext added in v0.4.0

type MockEvalContext struct {
	StoppedCalled bool
	StoppedValue  <-chan struct{}

	HookCalled bool
	HookHook   Hook
	HookError  error

	InputCalled bool
	InputInput  UIInput

	InitProviderCalled   bool
	InitProviderType     string
	InitProviderAddr     addrs.AbsProviderConfig
	InitProviderProvider providers.Interface
	InitProviderError    error

	ProviderCalled   bool
	ProviderAddr     addrs.AbsProviderConfig
	ProviderProvider providers.Interface

	ProviderSchemaCalled bool
	ProviderSchemaAddr   addrs.AbsProviderConfig
	ProviderSchemaSchema *ProviderSchema

	CloseProviderCalled   bool
	CloseProviderAddr     addrs.AbsProviderConfig
	CloseProviderProvider providers.Interface

	ProviderInputCalled bool
	ProviderInputAddr   addrs.AbsProviderConfig
	ProviderInputValues map[string]cty.Value

	SetProviderInputCalled bool
	SetProviderInputAddr   addrs.AbsProviderConfig
	SetProviderInputValues map[string]cty.Value

	ConfigureProviderCalled bool
	ConfigureProviderAddr   addrs.AbsProviderConfig
	ConfigureProviderConfig cty.Value
	ConfigureProviderDiags  tfdiags.Diagnostics

	InitProvisionerCalled      bool
	InitProvisionerName        string
	InitProvisionerProvisioner provisioners.Interface
	InitProvisionerError       error

	ProvisionerCalled      bool
	ProvisionerName        string
	ProvisionerProvisioner provisioners.Interface

	ProvisionerSchemaCalled bool
	ProvisionerSchemaName   string
	ProvisionerSchemaSchema *configschema.Block

	CloseProvisionerCalled      bool
	CloseProvisionerName        string
	CloseProvisionerProvisioner provisioners.Interface

	EvaluateBlockCalled     bool
	EvaluateBlockBody       hcl.Body
	EvaluateBlockSchema     *configschema.Block
	EvaluateBlockSelf       addrs.Referenceable
	EvaluateBlockKeyData    InstanceKeyEvalData
	EvaluateBlockResultFunc func(
		body hcl.Body,
		schema *configschema.Block,
		self addrs.Referenceable,
		keyData InstanceKeyEvalData,
	) (cty.Value, hcl.Body, tfdiags.Diagnostics) // overrides the other values below, if set
	EvaluateBlockResult       cty.Value
	EvaluateBlockExpandedBody hcl.Body
	EvaluateBlockDiags        tfdiags.Diagnostics

	EvaluateExprCalled     bool
	EvaluateExprExpr       hcl.Expression
	EvaluateExprWantType   cty.Type
	EvaluateExprSelf       addrs.Referenceable
	EvaluateExprResultFunc func(
		expr hcl.Expression,
		wantType cty.Type,
		self addrs.Referenceable,
	) (cty.Value, tfdiags.Diagnostics) // overrides the other values below, if set
	EvaluateExprResult cty.Value
	EvaluateExprDiags  tfdiags.Diagnostics

	EvaluationScopeCalled  bool
	EvaluationScopeSelf    addrs.Referenceable
	EvaluationScopeKeyData InstanceKeyEvalData
	EvaluationScopeScope   *lang.Scope

	PathCalled bool
	PathPath   addrs.ModuleInstance

	SetModuleCallArgumentsCalled bool
	SetModuleCallArgumentsModule addrs.ModuleCallInstance
	SetModuleCallArgumentsValues map[string]cty.Value

	GetVariableValueCalled bool
	GetVariableValueAddr   addrs.AbsInputVariableInstance
	GetVariableValueValue  cty.Value

	ChangesCalled  bool
	ChangesChanges *plans.ChangesSync

	StateCalled bool
	StateState  *states.SyncState

	RefreshStateCalled bool
	RefreshStateState  *states.SyncState

	InstanceExpanderCalled   bool
	InstanceExpanderExpander *instances.Expander
}

MockEvalContext is a mock version of EvalContext that can be used for tests.

func (*MockEvalContext) Changes added in v0.12.0

func (c *MockEvalContext) Changes() *plans.ChangesSync

func (*MockEvalContext) CloseProvider added in v0.6.0

func (c *MockEvalContext) CloseProvider(addr addrs.AbsProviderConfig) error

func (*MockEvalContext) CloseProvisioner added in v0.6.0

func (c *MockEvalContext) CloseProvisioner(n string) error

func (*MockEvalContext) ConfigureProvider added in v0.4.0

func (c *MockEvalContext) ConfigureProvider(addr addrs.AbsProviderConfig, cfg cty.Value) tfdiags.Diagnostics

func (*MockEvalContext) EvaluateBlock added in v0.12.0

func (c *MockEvalContext) EvaluateBlock(body hcl.Body, schema *configschema.Block, self addrs.Referenceable, keyData InstanceKeyEvalData) (cty.Value, hcl.Body, tfdiags.Diagnostics)

func (*MockEvalContext) EvaluateExpr added in v0.12.0

func (c *MockEvalContext) EvaluateExpr(expr hcl.Expression, wantType cty.Type, self addrs.Referenceable) (cty.Value, tfdiags.Diagnostics)

func (*MockEvalContext) EvaluationScope added in v0.12.0

func (c *MockEvalContext) EvaluationScope(self addrs.Referenceable, keyData InstanceKeyEvalData) *lang.Scope

func (*MockEvalContext) GetVariableValue added in v0.12.20

func (c *MockEvalContext) GetVariableValue(addr addrs.AbsInputVariableInstance) cty.Value

func (*MockEvalContext) Hook added in v0.4.0

func (c *MockEvalContext) Hook(fn func(Hook) (HookAction, error)) error

func (*MockEvalContext) InitProvider added in v0.4.0

func (*MockEvalContext) InitProvisioner added in v0.4.0

func (c *MockEvalContext) InitProvisioner(n string) error

func (*MockEvalContext) Input added in v0.4.0

func (c *MockEvalContext) Input() UIInput

func (*MockEvalContext) InstanceExpander added in v0.13.0

func (c *MockEvalContext) InstanceExpander() *instances.Expander

func (*MockEvalContext) Path added in v0.4.0

func (*MockEvalContext) Provider added in v0.4.0

func (*MockEvalContext) ProviderInput added in v0.4.0

func (c *MockEvalContext) ProviderInput(addr addrs.AbsProviderConfig) map[string]cty.Value

func (*MockEvalContext) ProviderSchema added in v0.12.0

func (c *MockEvalContext) ProviderSchema(addr addrs.AbsProviderConfig) *ProviderSchema

func (*MockEvalContext) Provisioner added in v0.4.0

func (c *MockEvalContext) Provisioner(n string) provisioners.Interface

func (*MockEvalContext) ProvisionerSchema added in v0.12.0

func (c *MockEvalContext) ProvisionerSchema(n string) *configschema.Block

func (*MockEvalContext) RefreshState added in v0.14.0

func (c *MockEvalContext) RefreshState() *states.SyncState

func (*MockEvalContext) SetModuleCallArguments added in v0.12.0

func (c *MockEvalContext) SetModuleCallArguments(n addrs.ModuleCallInstance, values map[string]cty.Value)

func (*MockEvalContext) SetProviderInput added in v0.4.0

func (c *MockEvalContext) SetProviderInput(addr addrs.AbsProviderConfig, vals map[string]cty.Value)

func (*MockEvalContext) State added in v0.4.0

func (c *MockEvalContext) State() *states.SyncState

func (*MockEvalContext) Stopped added in v0.9.0

func (c *MockEvalContext) Stopped() <-chan struct{}

func (*MockEvalContext) WithPath added in v0.13.0

func (c *MockEvalContext) WithPath(path addrs.ModuleInstance) EvalContext

type MockHook

type MockHook struct {
	sync.Mutex

	PreApplyCalled       bool
	PreApplyAddr         addrs.AbsResourceInstance
	PreApplyGen          states.Generation
	PreApplyAction       plans.Action
	PreApplyPriorState   cty.Value
	PreApplyPlannedState cty.Value
	PreApplyReturn       HookAction
	PreApplyError        error

	PostApplyCalled      bool
	PostApplyAddr        addrs.AbsResourceInstance
	PostApplyGen         states.Generation
	PostApplyNewState    cty.Value
	PostApplyError       error
	PostApplyReturn      HookAction
	PostApplyReturnError error
	PostApplyFn          func(addrs.AbsResourceInstance, states.Generation, cty.Value, error) (HookAction, error)

	PreDiffCalled        bool
	PreDiffAddr          addrs.AbsResourceInstance
	PreDiffGen           states.Generation
	PreDiffPriorState    cty.Value
	PreDiffProposedState cty.Value
	PreDiffReturn        HookAction
	PreDiffError         error

	PostDiffCalled       bool
	PostDiffAddr         addrs.AbsResourceInstance
	PostDiffGen          states.Generation
	PostDiffAction       plans.Action
	PostDiffPriorState   cty.Value
	PostDiffPlannedState cty.Value
	PostDiffReturn       HookAction
	PostDiffError        error

	PreProvisionInstanceCalled bool
	PreProvisionInstanceAddr   addrs.AbsResourceInstance
	PreProvisionInstanceState  cty.Value
	PreProvisionInstanceReturn HookAction
	PreProvisionInstanceError  error

	PostProvisionInstanceCalled bool
	PostProvisionInstanceAddr   addrs.AbsResourceInstance
	PostProvisionInstanceState  cty.Value
	PostProvisionInstanceReturn HookAction
	PostProvisionInstanceError  error

	PreProvisionInstanceStepCalled          bool
	PreProvisionInstanceStepAddr            addrs.AbsResourceInstance
	PreProvisionInstanceStepProvisionerType string
	PreProvisionInstanceStepReturn          HookAction
	PreProvisionInstanceStepError           error

	PostProvisionInstanceStepCalled          bool
	PostProvisionInstanceStepAddr            addrs.AbsResourceInstance
	PostProvisionInstanceStepProvisionerType string
	PostProvisionInstanceStepErrorArg        error
	PostProvisionInstanceStepReturn          HookAction
	PostProvisionInstanceStepError           error

	ProvisionOutputCalled          bool
	ProvisionOutputAddr            addrs.AbsResourceInstance
	ProvisionOutputProvisionerType string
	ProvisionOutputMessage         string

	PreRefreshCalled     bool
	PreRefreshAddr       addrs.AbsResourceInstance
	PreRefreshGen        states.Generation
	PreRefreshPriorState cty.Value
	PreRefreshReturn     HookAction
	PreRefreshError      error

	PostRefreshCalled     bool
	PostRefreshAddr       addrs.AbsResourceInstance
	PostRefreshGen        states.Generation
	PostRefreshPriorState cty.Value
	PostRefreshNewState   cty.Value
	PostRefreshReturn     HookAction
	PostRefreshError      error

	PreImportStateCalled bool
	PreImportStateAddr   addrs.AbsResourceInstance
	PreImportStateID     string
	PreImportStateReturn HookAction
	PreImportStateError  error

	PostImportStateCalled    bool
	PostImportStateAddr      addrs.AbsResourceInstance
	PostImportStateNewStates []providers.ImportedResource
	PostImportStateReturn    HookAction
	PostImportStateError     error

	PostStateUpdateCalled bool
	PostStateUpdateState  *states.State
	PostStateUpdateReturn HookAction
	PostStateUpdateError  error
}

MockHook is an implementation of Hook that can be used for tests. It records all of its function calls.

func (*MockHook) PostApply

func (h *MockHook) PostApply(addr addrs.AbsResourceInstance, gen states.Generation, newState cty.Value, err error) (HookAction, error)

func (*MockHook) PostDiff

func (h *MockHook) PostDiff(addr addrs.AbsResourceInstance, gen states.Generation, action plans.Action, priorState, plannedNewState cty.Value) (HookAction, error)

func (*MockHook) PostImportState added in v0.7.0

func (h *MockHook) PostImportState(addr addrs.AbsResourceInstance, imported []providers.ImportedResource) (HookAction, error)

func (*MockHook) PostProvisionInstance added in v0.12.0

func (h *MockHook) PostProvisionInstance(addr addrs.AbsResourceInstance, state cty.Value) (HookAction, error)

func (*MockHook) PostProvisionInstanceStep added in v0.12.0

func (h *MockHook) PostProvisionInstanceStep(addr addrs.AbsResourceInstance, typeName string, err error) (HookAction, error)

func (*MockHook) PostRefresh

func (h *MockHook) PostRefresh(addr addrs.AbsResourceInstance, gen states.Generation, priorState cty.Value, newState cty.Value) (HookAction, error)

func (*MockHook) PostStateUpdate added in v0.4.0

func (h *MockHook) PostStateUpdate(new *states.State) (HookAction, error)

func (*MockHook) PreApply

func (h *MockHook) PreApply(addr addrs.AbsResourceInstance, gen states.Generation, action plans.Action, priorState, plannedNewState cty.Value) (HookAction, error)

func (*MockHook) PreDiff

func (h *MockHook) PreDiff(addr addrs.AbsResourceInstance, gen states.Generation, priorState, proposedNewState cty.Value) (HookAction, error)

func (*MockHook) PreImportState added in v0.7.0

func (h *MockHook) PreImportState(addr addrs.AbsResourceInstance, importID string) (HookAction, error)

func (*MockHook) PreProvisionInstance added in v0.12.0

func (h *MockHook) PreProvisionInstance(addr addrs.AbsResourceInstance, state cty.Value) (HookAction, error)

func (*MockHook) PreProvisionInstanceStep added in v0.12.0

func (h *MockHook) PreProvisionInstanceStep(addr addrs.AbsResourceInstance, typeName string) (HookAction, error)

func (*MockHook) PreRefresh

func (h *MockHook) PreRefresh(addr addrs.AbsResourceInstance, gen states.Generation, priorState cty.Value) (HookAction, error)

func (*MockHook) ProvisionOutput added in v0.3.0

func (h *MockHook) ProvisionOutput(addr addrs.AbsResourceInstance, typeName string, line string)

type MockProvider added in v0.12.0

type MockProvider struct {
	sync.Mutex

	// Anything you want, in case you need to store extra data with the mock.
	Meta interface{}

	GetSchemaCalled bool
	GetSchemaReturn *ProviderSchema // This is using ProviderSchema directly rather than providers.GetSchemaResponse for compatibility with old tests

	PrepareProviderConfigCalled   bool
	PrepareProviderConfigResponse providers.PrepareProviderConfigResponse
	PrepareProviderConfigRequest  providers.PrepareProviderConfigRequest
	PrepareProviderConfigFn       func(providers.PrepareProviderConfigRequest) providers.PrepareProviderConfigResponse

	ValidateResourceTypeConfigCalled   bool
	ValidateResourceTypeConfigTypeName string
	ValidateResourceTypeConfigResponse providers.ValidateResourceTypeConfigResponse
	ValidateResourceTypeConfigRequest  providers.ValidateResourceTypeConfigRequest
	ValidateResourceTypeConfigFn       func(providers.ValidateResourceTypeConfigRequest) providers.ValidateResourceTypeConfigResponse

	ValidateDataSourceConfigCalled   bool
	ValidateDataSourceConfigTypeName string
	ValidateDataSourceConfigResponse providers.ValidateDataSourceConfigResponse
	ValidateDataSourceConfigRequest  providers.ValidateDataSourceConfigRequest
	ValidateDataSourceConfigFn       func(providers.ValidateDataSourceConfigRequest) providers.ValidateDataSourceConfigResponse

	UpgradeResourceStateCalled   bool
	UpgradeResourceStateTypeName string
	UpgradeResourceStateResponse providers.UpgradeResourceStateResponse
	UpgradeResourceStateRequest  providers.UpgradeResourceStateRequest
	UpgradeResourceStateFn       func(providers.UpgradeResourceStateRequest) providers.UpgradeResourceStateResponse

	ConfigureCalled   bool
	ConfigureResponse providers.ConfigureResponse
	ConfigureRequest  providers.ConfigureRequest
	ConfigureFn       func(providers.ConfigureRequest) providers.ConfigureResponse

	StopCalled   bool
	StopFn       func() error
	StopResponse error

	ReadResourceCalled   bool
	ReadResourceResponse providers.ReadResourceResponse
	ReadResourceRequest  providers.ReadResourceRequest
	ReadResourceFn       func(providers.ReadResourceRequest) providers.ReadResourceResponse

	PlanResourceChangeCalled   bool
	PlanResourceChangeResponse providers.PlanResourceChangeResponse
	PlanResourceChangeRequest  providers.PlanResourceChangeRequest
	PlanResourceChangeFn       func(providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse

	ApplyResourceChangeCalled   bool
	ApplyResourceChangeResponse providers.ApplyResourceChangeResponse
	ApplyResourceChangeRequest  providers.ApplyResourceChangeRequest
	ApplyResourceChangeFn       func(providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse

	ImportResourceStateCalled   bool
	ImportResourceStateResponse providers.ImportResourceStateResponse
	ImportResourceStateRequest  providers.ImportResourceStateRequest
	ImportResourceStateFn       func(providers.ImportResourceStateRequest) providers.ImportResourceStateResponse
	// Legacy return type for existing tests, which will be shimmed into an
	// ImportResourceStateResponse if set
	ImportStateReturn []*InstanceState

	ReadDataSourceCalled   bool
	ReadDataSourceResponse providers.ReadDataSourceResponse
	ReadDataSourceRequest  providers.ReadDataSourceRequest
	ReadDataSourceFn       func(providers.ReadDataSourceRequest) providers.ReadDataSourceResponse

	CloseCalled bool
	CloseError  error
}

MockProvider implements providers.Interface but mocks out all the calls for testing purposes.

func (*MockProvider) ApplyResourceChange added in v0.12.0

func (*MockProvider) Close added in v0.12.0

func (p *MockProvider) Close() error

func (*MockProvider) Configure added in v0.12.0

func (*MockProvider) GetSchema added in v0.12.0

func (p *MockProvider) GetSchema() providers.GetSchemaResponse

func (*MockProvider) ImportResourceState added in v0.12.0

func (*MockProvider) PlanResourceChange added in v0.12.0

func (*MockProvider) PrepareProviderConfig added in v0.12.0

func (*MockProvider) ReadDataSource added in v0.12.0

func (*MockProvider) ReadResource added in v0.12.0

func (*MockProvider) Stop added in v0.12.0

func (p *MockProvider) Stop() error

func (*MockProvider) UpgradeResourceState added in v0.12.0

func (*MockProvider) ValidateDataSourceConfig added in v0.12.0

func (*MockProvider) ValidateResourceTypeConfig added in v0.12.0

type MockProvisioner added in v0.12.0

type MockProvisioner struct {
	sync.Mutex
	// Anything you want, in case you need to store extra data with the mock.
	Meta interface{}

	GetSchemaCalled   bool
	GetSchemaResponse provisioners.GetSchemaResponse

	ValidateProvisionerConfigCalled   bool
	ValidateProvisionerConfigRequest  provisioners.ValidateProvisionerConfigRequest
	ValidateProvisionerConfigResponse provisioners.ValidateProvisionerConfigResponse
	ValidateProvisionerConfigFn       func(provisioners.ValidateProvisionerConfigRequest) provisioners.ValidateProvisionerConfigResponse

	ProvisionResourceCalled   bool
	ProvisionResourceRequest  provisioners.ProvisionResourceRequest
	ProvisionResourceResponse provisioners.ProvisionResourceResponse
	ProvisionResourceFn       func(provisioners.ProvisionResourceRequest) provisioners.ProvisionResourceResponse

	StopCalled   bool
	StopResponse error
	StopFn       func() error

	CloseCalled   bool
	CloseResponse error
	CloseFn       func() error
}

MockProvisioner implements provisioners.Interface but mocks out all the calls for testing purposes.

func (*MockProvisioner) Close added in v0.12.0

func (p *MockProvisioner) Close() error

func (*MockProvisioner) GetSchema added in v0.12.0

func (*MockProvisioner) ProvisionResource added in v0.12.0

func (*MockProvisioner) Stop added in v0.12.0

func (p *MockProvisioner) Stop() error

func (*MockProvisioner) ValidateProvisionerConfig added in v0.12.0

type MockResourceProvider

type MockResourceProvider struct {
	sync.Mutex

	// Anything you want, in case you need to store extra data with the mock.
	Meta interface{}

	CloseCalled                    bool
	CloseError                     error
	GetSchemaCalled                bool
	GetSchemaRequest               *ProviderSchemaRequest
	GetSchemaReturn                *ProviderSchema
	GetSchemaReturnError           error
	InputCalled                    bool
	InputInput                     UIInput
	InputConfig                    *ResourceConfig
	InputReturnConfig              *ResourceConfig
	InputReturnError               error
	InputFn                        func(UIInput, *ResourceConfig) (*ResourceConfig, error)
	ApplyCalled                    bool
	ApplyInfo                      *InstanceInfo
	ApplyState                     *InstanceState
	ApplyDiff                      *InstanceDiff
	ApplyFn                        func(*InstanceInfo, *InstanceState, *InstanceDiff) (*InstanceState, error)
	ApplyReturn                    *InstanceState
	ApplyReturnError               error
	ConfigureCalled                bool
	ConfigureConfig                *ResourceConfig
	ConfigureFn                    func(*ResourceConfig) error
	ConfigureReturnError           error
	DiffCalled                     bool
	DiffInfo                       *InstanceInfo
	DiffState                      *InstanceState
	DiffDesired                    *ResourceConfig
	DiffFn                         func(*InstanceInfo, *InstanceState, *ResourceConfig) (*InstanceDiff, error)
	DiffReturn                     *InstanceDiff
	DiffReturnError                error
	RefreshCalled                  bool
	RefreshInfo                    *InstanceInfo
	RefreshState                   *InstanceState
	RefreshFn                      func(*InstanceInfo, *InstanceState) (*InstanceState, error)
	RefreshReturn                  *InstanceState
	RefreshReturnError             error
	ResourcesCalled                bool
	ResourcesReturn                []ResourceType
	ReadDataApplyCalled            bool
	ReadDataApplyInfo              *InstanceInfo
	ReadDataApplyDiff              *InstanceDiff
	ReadDataApplyFn                func(*InstanceInfo, *InstanceDiff) (*InstanceState, error)
	ReadDataApplyReturn            *InstanceState
	ReadDataApplyReturnError       error
	ReadDataDiffCalled             bool
	ReadDataDiffInfo               *InstanceInfo
	ReadDataDiffDesired            *ResourceConfig
	ReadDataDiffFn                 func(*InstanceInfo, *ResourceConfig) (*InstanceDiff, error)
	ReadDataDiffReturn             *InstanceDiff
	ReadDataDiffReturnError        error
	StopCalled                     bool
	StopFn                         func() error
	StopReturnError                error
	DataSourcesCalled              bool
	DataSourcesReturn              []DataSource
	ValidateCalled                 bool
	ValidateConfig                 *ResourceConfig
	ValidateFn                     func(*ResourceConfig) ([]string, []error)
	ValidateReturnWarns            []string
	ValidateReturnErrors           []error
	ValidateResourceFn             func(string, *ResourceConfig) ([]string, []error)
	ValidateResourceCalled         bool
	ValidateResourceType           string
	ValidateResourceConfig         *ResourceConfig
	ValidateResourceReturnWarns    []string
	ValidateResourceReturnErrors   []error
	ValidateDataSourceFn           func(string, *ResourceConfig) ([]string, []error)
	ValidateDataSourceCalled       bool
	ValidateDataSourceType         string
	ValidateDataSourceConfig       *ResourceConfig
	ValidateDataSourceReturnWarns  []string
	ValidateDataSourceReturnErrors []error

	ImportStateCalled      bool
	ImportStateInfo        *InstanceInfo
	ImportStateID          string
	ImportStateReturn      []*InstanceState
	ImportStateReturnError error
	ImportStateFn          func(*InstanceInfo, string) ([]*InstanceState, error)
}

MockResourceProvider implements ResourceProvider but mocks out all the calls for testing purposes.

func (*MockResourceProvider) Apply

func (p *MockResourceProvider) Apply(
	info *InstanceInfo,
	state *InstanceState,
	diff *InstanceDiff) (*InstanceState, error)

func (*MockResourceProvider) Close added in v0.6.0

func (p *MockResourceProvider) Close() error

func (*MockResourceProvider) Configure

func (p *MockResourceProvider) Configure(c *ResourceConfig) error

func (*MockResourceProvider) DataSources added in v0.7.0

func (p *MockResourceProvider) DataSources() []DataSource

func (*MockResourceProvider) Diff

func (p *MockResourceProvider) Diff(
	info *InstanceInfo,
	state *InstanceState,
	desired *ResourceConfig) (*InstanceDiff, error)

func (*MockResourceProvider) GetSchema added in v0.10.8

func (*MockResourceProvider) ImportState added in v0.7.0

func (p *MockResourceProvider) ImportState(info *InstanceInfo, id string) ([]*InstanceState, error)

func (*MockResourceProvider) Input added in v0.3.0

func (*MockResourceProvider) ReadDataApply added in v0.7.0

func (p *MockResourceProvider) ReadDataApply(
	info *InstanceInfo,
	d *InstanceDiff) (*InstanceState, error)

func (*MockResourceProvider) ReadDataDiff added in v0.7.0

func (p *MockResourceProvider) ReadDataDiff(
	info *InstanceInfo,
	desired *ResourceConfig) (*InstanceDiff, error)

func (*MockResourceProvider) Refresh

func (*MockResourceProvider) Resources

func (p *MockResourceProvider) Resources() []ResourceType

func (*MockResourceProvider) Stop added in v0.8.0

func (p *MockResourceProvider) Stop() error

func (*MockResourceProvider) Validate

func (p *MockResourceProvider) Validate(c *ResourceConfig) ([]string, []error)

func (*MockResourceProvider) ValidateDataSource added in v0.7.0

func (p *MockResourceProvider) ValidateDataSource(t string, c *ResourceConfig) ([]string, []error)

func (*MockResourceProvider) ValidateResource

func (p *MockResourceProvider) ValidateResource(t string, c *ResourceConfig) ([]string, []error)

type MockResourceProvisioner

type MockResourceProvisioner struct {
	sync.Mutex
	// Anything you want, in case you need to store extra data with the mock.
	Meta interface{}

	GetConfigSchemaCalled       bool
	GetConfigSchemaReturnSchema *configschema.Block
	GetConfigSchemaReturnError  error

	ApplyCalled      bool
	ApplyOutput      UIOutput
	ApplyState       *InstanceState
	ApplyConfig      *ResourceConfig
	ApplyFn          func(*InstanceState, *ResourceConfig) error
	ApplyReturnError error

	ValidateCalled       bool
	ValidateConfig       *ResourceConfig
	ValidateFn           func(c *ResourceConfig) ([]string, []error)
	ValidateReturnWarns  []string
	ValidateReturnErrors []error

	StopCalled      bool
	StopFn          func() error
	StopReturnError error
}

MockResourceProvisioner implements ResourceProvisioner but mocks out all the calls for testing purposes.

func (*MockResourceProvisioner) Apply

func (p *MockResourceProvisioner) Apply(
	output UIOutput,
	state *InstanceState,
	c *ResourceConfig) error

func (*MockResourceProvisioner) GetConfigSchema added in v0.12.0

func (p *MockResourceProvisioner) GetConfigSchema() (*configschema.Block, error)

func (*MockResourceProvisioner) Stop added in v0.9.0

func (p *MockResourceProvisioner) Stop() error

func (*MockResourceProvisioner) Validate

func (p *MockResourceProvisioner) Validate(c *ResourceConfig) ([]string, []error)

type MockUIInput added in v0.3.0

type MockUIInput struct {
	InputCalled       bool
	InputOpts         *InputOpts
	InputReturnMap    map[string]string
	InputReturnString string
	InputReturnError  error
	InputFn           func(*InputOpts) (string, error)
}

MockUIInput is an implementation of UIInput that can be used for tests.

func (*MockUIInput) Input added in v0.3.0

func (i *MockUIInput) Input(ctx context.Context, opts *InputOpts) (string, error)

type MockUIOutput added in v0.3.0

type MockUIOutput struct {
	sync.Mutex
	OutputCalled  bool
	OutputMessage string
	OutputFn      func(string)
}

MockUIOutput is an implementation of UIOutput that can be used for tests.

func (*MockUIOutput) Output added in v0.3.0

func (o *MockUIOutput) Output(v string)

type ModuleDiff added in v0.3.0

type ModuleDiff struct {
	Path      []string
	Resources map[string]*InstanceDiff
	Destroy   bool // Set only by the destroy plan
}

ModuleDiff tracks the differences between resources to apply within a single module.

func (*ModuleDiff) ChangeType added in v0.3.0

func (d *ModuleDiff) ChangeType() DiffChangeType

ChangeType returns the type of changes that the diff for this module includes.

At a module level, this will only be DiffNone, DiffUpdate, DiffDestroy, or DiffCreate. If an instance within the module has a DiffDestroyCreate then this will register as a DiffCreate for a module.

func (*ModuleDiff) Empty added in v0.3.0

func (d *ModuleDiff) Empty() bool

Empty returns true if the diff has no changes within this module.

func (*ModuleDiff) Instances added in v0.3.0

func (d *ModuleDiff) Instances(id string) []*InstanceDiff

Instances returns the instance diffs for the id given. This can return multiple instance diffs if there are counts within the resource.

func (*ModuleDiff) IsRoot added in v0.3.0

func (d *ModuleDiff) IsRoot() bool

IsRoot says whether or not this module diff is for the root module.

func (*ModuleDiff) String added in v0.3.0

func (d *ModuleDiff) String() string

String outputs the diff in a long but command-line friendly output format that users can read to quickly inspect a diff.

type ModuleExpansionTransformer added in v0.13.0

type ModuleExpansionTransformer struct {
	Config *configs.Config

	// Concrete allows injection of a wrapped module node by the graph builder
	// to alter the evaluation behavior.
	Concrete ConcreteModuleNodeFunc
	// contains filtered or unexported fields
}

ModuleExpansionTransformer is a GraphTransformer that adds graph nodes representing the possible expansion of each module call in the configuration, and ensures that any nodes representing objects declared within a module are dependent on the expansion node so that they will be visited only after the module expansion has been decided.

This transform must be applied only after all nodes representing objects that can be contained within modules have already been added.

func (*ModuleExpansionTransformer) Transform added in v0.13.0

func (t *ModuleExpansionTransformer) Transform(g *Graph) error

type ModuleState added in v0.3.0

type ModuleState struct {
	// Path is the import path from the root module. Modules imports are
	// always disjoint, so the path represents amodule tree
	Path []string `json:"path"`

	// Locals are kept only transiently in-memory, because we can always
	// re-compute them.
	Locals map[string]interface{} `json:"-"`

	// Outputs declared by the module and maintained for each module
	// even though only the root module technically needs to be kept.
	// This allows operators to inspect values at the boundaries.
	Outputs map[string]*OutputState `json:"outputs"`

	// Resources is a mapping of the logically named resource to
	// the state of the resource. Each resource may actually have
	// N instances underneath, although a user only needs to think
	// about the 1:1 case.
	Resources map[string]*ResourceState `json:"resources"`

	// Dependencies are a list of things that this module relies on
	// existing to remain intact. For example: an module may depend
	// on a VPC ID given by an aws_vpc resource.
	//
	// Terraform uses this information to build valid destruction
	// orders and to warn the user if they're destroying a module that
	// another resource depends on.
	//
	// Things can be put into this list that may not be managed by
	// Terraform. If Terraform doesn't find a matching ID in the
	// overall state, then it assumes it isn't managed and doesn't
	// worry about it.
	Dependencies []string `json:"depends_on"`
	// contains filtered or unexported fields
}

ModuleState is used to track all the state relevant to a single module. Previous to Terraform 0.3, all state belonged to the "root" module.

func (*ModuleState) Empty added in v0.11.0

func (m *ModuleState) Empty() bool

func (*ModuleState) Equal added in v0.4.0

func (m *ModuleState) Equal(other *ModuleState) bool

Equal tests whether one module state is equal to another.

func (*ModuleState) IsDescendent added in v0.7.2

func (m *ModuleState) IsDescendent(other *ModuleState) bool

IsDescendent returns true if other is a descendent of this module.

func (*ModuleState) IsRoot added in v0.3.0

func (m *ModuleState) IsRoot() bool

IsRoot says whether or not this module diff is for the root module.

func (*ModuleState) Lock added in v0.7.3

func (s *ModuleState) Lock()

func (*ModuleState) Orphans added in v0.3.0

func (m *ModuleState) Orphans(c *configs.Module) []addrs.ResourceInstance

Orphans returns a list of keys of resources that are in the State but aren't present in the configuration itself. Hence, these keys represent the state of resources that are orphans.

func (*ModuleState) RemovedOutputs added in v0.11.0

func (s *ModuleState) RemovedOutputs(outputs map[string]*configs.Output) []addrs.OutputValue

RemovedOutputs returns a list of outputs that are in the State but aren't present in the configuration itself.

func (*ModuleState) String added in v0.3.0

func (m *ModuleState) String() string

func (*ModuleState) Unlock added in v0.7.3

func (s *ModuleState) Unlock()

func (*ModuleState) View added in v0.3.0

func (m *ModuleState) View(id string) *ModuleState

View returns a view with the given resource prefix.

type ModuleVariableTransformer added in v0.7.8

type ModuleVariableTransformer struct {
	Config *configs.Config
}

ModuleVariableTransformer is a GraphTransformer that adds all the variables in the configuration to the graph.

Any "variable" block present in any non-root module is included here, even if a particular variable is not referenced from anywhere.

The transform will produce errors if a call to a module does not conform to the expected set of arguments, but this transformer is not in a good position to return errors and so the validate walk should include specific steps for validating module blocks, separate from this transform.

func (*ModuleVariableTransformer) Transform added in v0.7.8

func (t *ModuleVariableTransformer) Transform(g *Graph) error

type NilHook

type NilHook struct{}

NilHook is a Hook implementation that does nothing. It exists only to simplify implementing hooks. You can embed this into your Hook implementation and only implement the functions you are interested in.

func (*NilHook) PostApply

func (*NilHook) PostApply(addr addrs.AbsResourceInstance, gen states.Generation, newState cty.Value, err error) (HookAction, error)

func (*NilHook) PostDiff

func (*NilHook) PostDiff(addr addrs.AbsResourceInstance, gen states.Generation, action plans.Action, priorState, plannedNewState cty.Value) (HookAction, error)

func (*NilHook) PostImportState added in v0.7.0

func (*NilHook) PostImportState(addr addrs.AbsResourceInstance, imported []providers.ImportedResource) (HookAction, error)

func (*NilHook) PostProvisionInstance added in v0.12.0

func (*NilHook) PostProvisionInstance(addr addrs.AbsResourceInstance, state cty.Value) (HookAction, error)

func (*NilHook) PostProvisionInstanceStep added in v0.12.0

func (*NilHook) PostProvisionInstanceStep(addr addrs.AbsResourceInstance, typeName string, err error) (HookAction, error)

func (*NilHook) PostRefresh

func (*NilHook) PostRefresh(addr addrs.AbsResourceInstance, gen states.Generation, priorState cty.Value, newState cty.Value) (HookAction, error)

func (*NilHook) PostStateUpdate added in v0.4.0

func (*NilHook) PostStateUpdate(new *states.State) (HookAction, error)

func (*NilHook) PreApply

func (*NilHook) PreApply(addr addrs.AbsResourceInstance, gen states.Generation, action plans.Action, priorState, plannedNewState cty.Value) (HookAction, error)

func (*NilHook) PreDiff

func (*NilHook) PreDiff(addr addrs.AbsResourceInstance, gen states.Generation, priorState, proposedNewState cty.Value) (HookAction, error)

func (*NilHook) PreImportState added in v0.7.0

func (*NilHook) PreImportState(addr addrs.AbsResourceInstance, importID string) (HookAction, error)

func (*NilHook) PreProvisionInstance added in v0.12.0

func (*NilHook) PreProvisionInstance(addr addrs.AbsResourceInstance, state cty.Value) (HookAction, error)

func (*NilHook) PreProvisionInstanceStep added in v0.12.0

func (*NilHook) PreProvisionInstanceStep(addr addrs.AbsResourceInstance, typeName string) (HookAction, error)

func (*NilHook) PreRefresh

func (*NilHook) PreRefresh(addr addrs.AbsResourceInstance, gen states.Generation, priorState cty.Value) (HookAction, error)

func (*NilHook) ProvisionOutput added in v0.3.0

func (*NilHook) ProvisionOutput(addr addrs.AbsResourceInstance, typeName string, line string)

type NodeAbstractProvider added in v0.7.8

type NodeAbstractProvider struct {
	Addr addrs.AbsProviderConfig

	Config *configs.Provider
	Schema *configschema.Block
}

NodeAbstractProvider represents a provider that has no associated operations. It registers all the common interfaces across operations for providers.

func (*NodeAbstractProvider) AttachProvider added in v0.7.8

func (n *NodeAbstractProvider) AttachProvider(c *configs.Provider)

GraphNodeAttachProvider

func (*NodeAbstractProvider) AttachProviderConfigSchema added in v0.12.0

func (n *NodeAbstractProvider) AttachProviderConfigSchema(schema *configschema.Block)

GraphNodeAttachProviderConfigSchema impl.

func (*NodeAbstractProvider) DotNode added in v0.8.0

func (n *NodeAbstractProvider) DotNode(name string, opts *dag.DotOpts) *dag.DotNode

GraphNodeDotter impl.

func (*NodeAbstractProvider) ModulePath added in v0.13.0

func (n *NodeAbstractProvider) ModulePath() addrs.Module

GraphNodeModulePath

func (*NodeAbstractProvider) Name added in v0.7.8

func (n *NodeAbstractProvider) Name() string

func (*NodeAbstractProvider) Path added in v0.7.8

GraphNodeModuleInstance

func (*NodeAbstractProvider) ProviderAddr added in v0.12.0

func (n *NodeAbstractProvider) ProviderAddr() addrs.AbsProviderConfig

GraphNodeProvider

func (*NodeAbstractProvider) ProviderConfig added in v0.7.8

func (n *NodeAbstractProvider) ProviderConfig() *configs.Provider

GraphNodeProvider

func (*NodeAbstractProvider) References added in v0.7.8

func (n *NodeAbstractProvider) References() []*addrs.Reference

GraphNodeReferencer

type NodeAbstractResource added in v0.7.8

type NodeAbstractResource struct {
	Addr addrs.ConfigResource

	Schema        *configschema.Block // Schema for processing the configuration body
	SchemaVersion uint64              // Schema version of "Schema", as decided by the provider
	Config        *configs.Resource   // Config is the resource in the config

	// ProviderMetas is the provider_meta configs for the module this resource belongs to
	ProviderMetas map[addrs.Provider]*configs.ProviderMeta

	ProvisionerSchemas map[string]*configschema.Block

	// Set from GraphNodeTargetable
	Targets []addrs.Targetable

	// The address of the provider this resource will use
	ResolvedProvider addrs.AbsProviderConfig
	// contains filtered or unexported fields
}

NodeAbstractResource represents a resource that has no associated operations. It registers all the interfaces for a resource that common across multiple operation types.

func NewNodeAbstractResource added in v0.12.0

func NewNodeAbstractResource(addr addrs.ConfigResource) *NodeAbstractResource

NewNodeAbstractResource creates an abstract resource graph node for the given absolute resource address.

func (*NodeAbstractResource) AttachProviderMetaConfigs added in v0.13.0

func (n *NodeAbstractResource) AttachProviderMetaConfigs(c map[addrs.Provider]*configs.ProviderMeta)

GraphNodeAttachProviderMetaConfigs impl

func (*NodeAbstractResource) AttachProvisionerSchema added in v0.12.0

func (n *NodeAbstractResource) AttachProvisionerSchema(name string, schema *configschema.Block)

GraphNodeProvisionerConsumer

func (*NodeAbstractResource) AttachResourceConfig added in v0.7.8

func (n *NodeAbstractResource) AttachResourceConfig(c *configs.Resource)

GraphNodeAttachResourceConfig

func (*NodeAbstractResource) AttachResourceDependencies added in v0.13.0

func (n *NodeAbstractResource) AttachResourceDependencies(deps []addrs.ConfigResource, force bool)

graphNodeAttachResourceDependencies

func (*NodeAbstractResource) AttachResourceSchema added in v0.12.0

func (n *NodeAbstractResource) AttachResourceSchema(schema *configschema.Block, version uint64)

GraphNodeAttachResourceSchema impl

func (*NodeAbstractResource) DependsOn added in v0.13.0

func (n *NodeAbstractResource) DependsOn() []*addrs.Reference

func (*NodeAbstractResource) DotNode added in v0.8.0

func (n *NodeAbstractResource) DotNode(name string, opts *dag.DotOpts) *dag.DotNode

GraphNodeDotter impl.

func (*NodeAbstractResource) ModulePath added in v0.13.0

func (n *NodeAbstractResource) ModulePath() addrs.Module

GraphNodeModulePath

func (*NodeAbstractResource) Name added in v0.7.8

func (n *NodeAbstractResource) Name() string

func (*NodeAbstractResource) ProvidedBy added in v0.7.8

func (n *NodeAbstractResource) ProvidedBy() (addrs.ProviderConfig, bool)

GraphNodeProviderConsumer

func (*NodeAbstractResource) Provider added in v0.13.0

func (n *NodeAbstractResource) Provider() addrs.Provider

GraphNodeProviderConsumer

func (*NodeAbstractResource) ProvisionedBy added in v0.7.8

func (n *NodeAbstractResource) ProvisionedBy() []string

GraphNodeProvisionerConsumer

func (*NodeAbstractResource) ReadResourceInstanceState added in v0.14.0

func (n *NodeAbstractResource) ReadResourceInstanceState(ctx EvalContext, addr addrs.AbsResourceInstance) (*states.ResourceInstanceObject, error)

ReadResourceInstanceState reads the current object for a specific instance in the state.

func (*NodeAbstractResource) ReferenceableAddrs added in v0.12.0

func (n *NodeAbstractResource) ReferenceableAddrs() []addrs.Referenceable

GraphNodeReferenceable

func (*NodeAbstractResource) References added in v0.7.8

func (n *NodeAbstractResource) References() []*addrs.Reference

GraphNodeReferencer

func (*NodeAbstractResource) ResourceAddr added in v0.7.8

func (n *NodeAbstractResource) ResourceAddr() addrs.ConfigResource

GraphNodeResource

func (*NodeAbstractResource) SetProvider added in v0.11.0

func (n *NodeAbstractResource) SetProvider(p addrs.AbsProviderConfig)

func (*NodeAbstractResource) SetTargets added in v0.7.8

func (n *NodeAbstractResource) SetTargets(targets []addrs.Targetable)

GraphNodeTargetable

type NodeAbstractResourceInstance added in v0.12.0

type NodeAbstractResourceInstance struct {
	NodeAbstractResource
	Addr addrs.AbsResourceInstance

	Dependencies []addrs.ConfigResource
	// contains filtered or unexported fields
}

NodeAbstractResourceInstance represents a resource instance with no associated operations. It embeds NodeAbstractResource but additionally contains an instance key, used to identify one of potentially many instances that were created from a resource in configuration, e.g. using the "count" or "for_each" arguments.

func NewNodeAbstractResourceInstance added in v0.12.0

func NewNodeAbstractResourceInstance(addr addrs.AbsResourceInstance) *NodeAbstractResourceInstance

NewNodeAbstractResourceInstance creates an abstract resource instance graph node for the given absolute resource instance address.

func (*NodeAbstractResourceInstance) AttachResourceState added in v0.12.0

func (n *NodeAbstractResourceInstance) AttachResourceState(s *states.Resource)

GraphNodeAttachResourceState

func (*NodeAbstractResourceInstance) Name added in v0.12.0

func (*NodeAbstractResourceInstance) Path added in v0.13.0

func (*NodeAbstractResourceInstance) ProvidedBy added in v0.12.0

GraphNodeProviderConsumer

func (*NodeAbstractResourceInstance) Provider added in v0.13.0

GraphNodeProviderConsumer

func (*NodeAbstractResourceInstance) ReferenceableAddrs added in v0.12.0

func (n *NodeAbstractResourceInstance) ReferenceableAddrs() []addrs.Referenceable

GraphNodeReferenceable

func (*NodeAbstractResourceInstance) References added in v0.12.0

func (n *NodeAbstractResourceInstance) References() []*addrs.Reference

GraphNodeReferencer

func (*NodeAbstractResourceInstance) ResourceInstanceAddr added in v0.12.0

func (n *NodeAbstractResourceInstance) ResourceInstanceAddr() addrs.AbsResourceInstance

GraphNodeResourceInstance

func (*NodeAbstractResourceInstance) StateDependencies added in v0.12.14

func (n *NodeAbstractResourceInstance) StateDependencies() []addrs.ConfigResource

StateDependencies returns the dependencies saved in the state.

type NodeApplyableOutput added in v0.7.8

type NodeApplyableOutput struct {
	Addr   addrs.AbsOutputValue
	Config *configs.Output // Config is the output in the config
	// If this is being evaluated during apply, we may have a change recorded already
	Change *plans.OutputChangeSrc
}

NodeApplyableOutput represents an output that is "applyable": it is ready to be applied.

func (*NodeApplyableOutput) DotNode added in v0.12.0

func (n *NodeApplyableOutput) DotNode(name string, opts *dag.DotOpts) *dag.DotNode

dag.GraphNodeDotter impl.

func (*NodeApplyableOutput) Execute added in v0.14.0

func (n *NodeApplyableOutput) Execute(ctx EvalContext, op walkOperation) error

GraphNodeExecutable

func (*NodeApplyableOutput) ModulePath added in v0.13.0

func (n *NodeApplyableOutput) ModulePath() addrs.Module

GraphNodeModulePath

func (*NodeApplyableOutput) Name added in v0.7.8

func (n *NodeApplyableOutput) Name() string

func (*NodeApplyableOutput) Path added in v0.7.8

GraphNodeModuleInstance

func (*NodeApplyableOutput) ReferenceOutside added in v0.12.0

func (n *NodeApplyableOutput) ReferenceOutside() (selfPath, referencePath addrs.Module)

GraphNodeReferenceOutside implementation

func (*NodeApplyableOutput) ReferenceableAddrs added in v0.12.0

func (n *NodeApplyableOutput) ReferenceableAddrs() []addrs.Referenceable

GraphNodeReferenceable

func (*NodeApplyableOutput) References added in v0.7.8

func (n *NodeApplyableOutput) References() []*addrs.Reference

GraphNodeReferencer

type NodeApplyableProvider added in v0.7.8

type NodeApplyableProvider struct {
	*NodeAbstractProvider
}

NodeApplyableProvider represents a provider during an apply.

func (*NodeApplyableProvider) ConfigureProvider added in v0.14.0

func (n *NodeApplyableProvider) ConfigureProvider(ctx EvalContext, provider providers.Interface, verifyConfigIsKnown bool) error

ConfigureProvider configures a provider that is already initialized and retrieved. If verifyConfigIsKnown is true, ConfigureProvider will return an error if the provider configVal is not wholly known and is meant only for use during import.

func (*NodeApplyableProvider) Execute added in v0.14.0

func (n *NodeApplyableProvider) Execute(ctx EvalContext, op walkOperation) error

GraphNodeExecutable

func (*NodeApplyableProvider) ValidateProvider added in v0.14.0

func (n *NodeApplyableProvider) ValidateProvider(ctx EvalContext, provider providers.Interface) error

type NodeApplyableResource added in v0.7.8

type NodeApplyableResource struct {
	*NodeAbstractResource

	Addr addrs.AbsResource
}

NodeApplyableResource represents a resource that is "applyable": it may need to have its record in the state adjusted to match configuration.

Unlike in the plan walk, this resource node does not DynamicExpand. Instead, it should be inserted into the same graph as any instances of the nodes with dependency edges ensuring that the resource is evaluated before any of its instances, which will turn ensure that the whole-resource record in the state is suitably prepared to receive any updates to instances.

func (*NodeApplyableResource) Execute added in v0.14.0

func (n *NodeApplyableResource) Execute(ctx EvalContext, op walkOperation) error

GraphNodeExecutable

func (*NodeApplyableResource) Path added in v0.13.0

func (*NodeApplyableResource) References added in v0.8.0

func (n *NodeApplyableResource) References() []*addrs.Reference

type NodeApplyableResourceInstance added in v0.12.0

type NodeApplyableResourceInstance struct {
	*NodeAbstractResourceInstance

	// If this node is forced to be CreateBeforeDestroy, we need to record that
	// in the state to.
	ForceCreateBeforeDestroy bool
	// contains filtered or unexported fields
}

NodeApplyableResourceInstance represents a resource instance that is "applyable": it is ready to be applied and is represented by a diff.

This node is for a specific instance of a resource. It will usually be accompanied in the graph by a NodeApplyableResource representing its containing resource, and should depend on that node to ensure that the state is properly prepared to receive changes to instances.

func (*NodeApplyableResourceInstance) AttachDependencies added in v0.12.14

func (n *NodeApplyableResourceInstance) AttachDependencies(deps []addrs.ConfigResource)

GraphNodeAttachDependencies

func (*NodeApplyableResourceInstance) CreateAddr added in v0.12.0

GraphNodeCreator

func (*NodeApplyableResourceInstance) CreateBeforeDestroy added in v0.13.0

func (n *NodeApplyableResourceInstance) CreateBeforeDestroy() bool

CreateBeforeDestroy returns this node's CreateBeforeDestroy status.

func (*NodeApplyableResourceInstance) Execute added in v0.14.0

func (n *NodeApplyableResourceInstance) Execute(ctx EvalContext, op walkOperation) error

GraphNodeExecutable

func (*NodeApplyableResourceInstance) ModifyCreateBeforeDestroy added in v0.13.0

func (n *NodeApplyableResourceInstance) ModifyCreateBeforeDestroy(v bool) error

func (*NodeApplyableResourceInstance) References added in v0.12.0

func (n *NodeApplyableResourceInstance) References() []*addrs.Reference

GraphNodeReferencer, overriding NodeAbstractResourceInstance

func (*NodeApplyableResourceInstance) SetPreallocatedDeposedKey added in v0.12.0

func (n *NodeApplyableResourceInstance) SetPreallocatedDeposedKey(key states.DeposedKey)

type NodeCountBoundary added in v0.7.8

type NodeCountBoundary struct {
	Config *configs.Config
}

NodeCountBoundary fixes up any transitions between "each modes" in objects saved in state, such as switching from NoEach to EachInt.

func (*NodeCountBoundary) Execute added in v0.14.0

func (n *NodeCountBoundary) Execute(ctx EvalContext, op walkOperation) error

GraphNodeExecutable

func (*NodeCountBoundary) Name added in v0.7.8

func (n *NodeCountBoundary) Name() string

type NodeDestroyDeposedResourceInstanceObject added in v0.12.0

type NodeDestroyDeposedResourceInstanceObject struct {
	*NodeAbstractResourceInstance
	DeposedKey states.DeposedKey
}

NodeDestroyDeposedResourceInstanceObject represents deposed resource instance objects during apply. Nodes of this type are inserted by DiffTransformer when the planned changeset contains "delete" changes for deposed instance objects, and its only supported operation is to destroy and then forget the associated object.

func (*NodeDestroyDeposedResourceInstanceObject) CreateBeforeDestroy added in v0.12.0

func (n *NodeDestroyDeposedResourceInstanceObject) CreateBeforeDestroy() bool

GraphNodeDestroyerCBD

func (*NodeDestroyDeposedResourceInstanceObject) DeposedInstanceObjectKey added in v0.12.0

func (n *NodeDestroyDeposedResourceInstanceObject) DeposedInstanceObjectKey() states.DeposedKey

func (*NodeDestroyDeposedResourceInstanceObject) DestroyAddr added in v0.12.0

GraphNodeDestroyer

func (*NodeDestroyDeposedResourceInstanceObject) Execute added in v0.14.0

func (n *NodeDestroyDeposedResourceInstanceObject) Execute(ctx EvalContext, op walkOperation) error

GraphNodeExecutable impl.

func (*NodeDestroyDeposedResourceInstanceObject) ModifyCreateBeforeDestroy added in v0.12.0

func (n *NodeDestroyDeposedResourceInstanceObject) ModifyCreateBeforeDestroy(v bool) error

GraphNodeDestroyerCBD

func (*NodeDestroyDeposedResourceInstanceObject) Name added in v0.12.0

func (*NodeDestroyDeposedResourceInstanceObject) ReferenceableAddrs added in v0.12.0

GraphNodeReferenceable implementation, overriding the one from NodeAbstractResourceInstance

func (*NodeDestroyDeposedResourceInstanceObject) References added in v0.12.0

GraphNodeReferencer implementation, overriding the one from NodeAbstractResourceInstance

type NodeDestroyResourceInstance added in v0.12.0

type NodeDestroyResourceInstance struct {
	*NodeAbstractResourceInstance

	// If DeposedKey is set to anything other than states.NotDeposed then
	// this node destroys a deposed object of the associated instance
	// rather than its current object.
	DeposedKey states.DeposedKey
}

NodeDestroyResourceInstance represents a resource instance that is to be destroyed.

func (*NodeDestroyResourceInstance) CreateBeforeDestroy added in v0.12.0

func (n *NodeDestroyResourceInstance) CreateBeforeDestroy() bool

GraphNodeDestroyerCBD

func (*NodeDestroyResourceInstance) DestroyAddr added in v0.12.0

GraphNodeDestroyer

func (*NodeDestroyResourceInstance) Execute added in v0.14.0

func (n *NodeDestroyResourceInstance) Execute(ctx EvalContext, op walkOperation) error

GraphNodeExecutable

func (*NodeDestroyResourceInstance) ModifyCreateBeforeDestroy added in v0.12.0

func (n *NodeDestroyResourceInstance) ModifyCreateBeforeDestroy(v bool) error

GraphNodeDestroyerCBD

func (*NodeDestroyResourceInstance) Name added in v0.12.0

func (*NodeDestroyResourceInstance) ReferenceableAddrs added in v0.12.0

func (n *NodeDestroyResourceInstance) ReferenceableAddrs() []addrs.Referenceable

GraphNodeReferenceable, overriding NodeAbstractResource

func (*NodeDestroyResourceInstance) References added in v0.12.0

func (n *NodeDestroyResourceInstance) References() []*addrs.Reference

GraphNodeReferencer, overriding NodeAbstractResource

type NodeDestroyableDataResourceInstance added in v0.12.0

type NodeDestroyableDataResourceInstance struct {
	*NodeAbstractResourceInstance
}

NodeDestroyableDataResourceInstance represents a resource that is "destroyable": it is ready to be destroyed.

func (*NodeDestroyableDataResourceInstance) Execute added in v0.14.0

func (n *NodeDestroyableDataResourceInstance) Execute(ctx EvalContext, op walkOperation) error

GraphNodeExecutable

type NodeDestroyableOutput added in v0.11.4

type NodeDestroyableOutput struct {
	Addr   addrs.AbsOutputValue
	Config *configs.Output // Config is the output in the config
}

NodeDestroyableOutput represents an output that is "destroyable": its application will remove the output from the state.

func (*NodeDestroyableOutput) DotNode added in v0.12.0

func (n *NodeDestroyableOutput) DotNode(name string, opts *dag.DotOpts) *dag.DotNode

dag.GraphNodeDotter impl.

func (*NodeDestroyableOutput) Execute added in v0.14.0

func (n *NodeDestroyableOutput) Execute(ctx EvalContext, op walkOperation) error

GraphNodeExecutable

func (*NodeDestroyableOutput) ModulePath added in v0.13.0

func (n *NodeDestroyableOutput) ModulePath() addrs.Module

GraphNodeModulePath

func (*NodeDestroyableOutput) Name added in v0.11.4

func (n *NodeDestroyableOutput) Name() string

type NodeEvalableProvider added in v0.12.0

type NodeEvalableProvider struct {
	*NodeAbstractProvider
}

NodeEvalableProvider represents a provider during an "eval" walk. This special provider node type just initializes a provider and fetches its schema, without configuring it or otherwise interacting with it.

func (*NodeEvalableProvider) Execute added in v0.14.0

func (n *NodeEvalableProvider) Execute(ctx EvalContext, op walkOperation) error

GraphNodeExecutable

type NodeLocal added in v0.10.3

type NodeLocal struct {
	Addr   addrs.AbsLocalValue
	Config *configs.Local
}

NodeLocal represents a named local value in a particular module.

Local value nodes only have one operation, common to all walk types: evaluate the result and place it in state.

func (*NodeLocal) DotNode added in v0.12.0

func (n *NodeLocal) DotNode(name string, opts *dag.DotOpts) *dag.DotNode

dag.GraphNodeDotter impl.

func (*NodeLocal) Execute added in v0.14.0

func (n *NodeLocal) Execute(ctx EvalContext, op walkOperation) error

GraphNodeExecutable NodeLocal.Execute is an Execute implementation that evaluates the expression for a local value and writes it into a transient part of the state.

func (*NodeLocal) ModulePath added in v0.13.0

func (n *NodeLocal) ModulePath() addrs.Module

GraphNodeModulePath

func (*NodeLocal) Name added in v0.10.3

func (n *NodeLocal) Name() string

func (*NodeLocal) Path added in v0.10.3

func (n *NodeLocal) Path() addrs.ModuleInstance

GraphNodeModuleInstance

func (*NodeLocal) ReferenceableAddrs added in v0.12.0

func (n *NodeLocal) ReferenceableAddrs() []addrs.Referenceable

GraphNodeReferenceable

func (*NodeLocal) References added in v0.10.3

func (n *NodeLocal) References() []*addrs.Reference

GraphNodeReferencer

type NodePlanDeposedResourceInstanceObject added in v0.12.0

type NodePlanDeposedResourceInstanceObject struct {
	*NodeAbstractResourceInstance
	DeposedKey states.DeposedKey
}

NodePlanDeposedResourceInstanceObject represents deposed resource instance objects during plan. These are distinct from the primary object for each resource instance since the only valid operation to do with them is to destroy them.

This node type is also used during the refresh walk to ensure that the record of a deposed object is up-to-date before we plan to destroy it.

func (*NodePlanDeposedResourceInstanceObject) DeposedInstanceObjectKey added in v0.12.0

func (n *NodePlanDeposedResourceInstanceObject) DeposedInstanceObjectKey() states.DeposedKey

func (*NodePlanDeposedResourceInstanceObject) Execute added in v0.14.0

func (n *NodePlanDeposedResourceInstanceObject) Execute(ctx EvalContext, op walkOperation) error

GraphNodeEvalable impl.

func (*NodePlanDeposedResourceInstanceObject) Name added in v0.12.0

func (*NodePlanDeposedResourceInstanceObject) ReferenceableAddrs added in v0.12.0

func (n *NodePlanDeposedResourceInstanceObject) ReferenceableAddrs() []addrs.Referenceable

GraphNodeReferenceable implementation, overriding the one from NodeAbstractResourceInstance

func (*NodePlanDeposedResourceInstanceObject) References added in v0.12.0

GraphNodeReferencer implementation, overriding the one from NodeAbstractResourceInstance

type NodePlanDestroyableResourceInstance added in v0.12.0

type NodePlanDestroyableResourceInstance struct {
	*NodeAbstractResourceInstance
}

NodePlanDestroyableResourceInstance represents a resource that is ready to be planned for destruction.

func (*NodePlanDestroyableResourceInstance) DestroyAddr added in v0.12.0

GraphNodeDestroyer

func (*NodePlanDestroyableResourceInstance) Execute added in v0.14.0

func (n *NodePlanDestroyableResourceInstance) Execute(ctx EvalContext, op walkOperation) error

GraphNodeEvalable

type NodePlannableResource added in v0.7.10

type NodePlannableResource struct {
	*NodeAbstractResource

	Addr addrs.AbsResource

	// ForceCreateBeforeDestroy might be set via our GraphNodeDestroyerCBD
	// during graph construction, if dependencies require us to force this
	// on regardless of what the configuration says.
	ForceCreateBeforeDestroy *bool
	// contains filtered or unexported fields
}

NodePlannableResource represents a resource that is "plannable": it is ready to be planned in order to create a diff.

func (*NodePlannableResource) CreateBeforeDestroy added in v0.12.0

func (n *NodePlannableResource) CreateBeforeDestroy() bool

GraphNodeDestroyerCBD

func (*NodePlannableResource) DynamicExpand added in v0.7.10

func (n *NodePlannableResource) DynamicExpand(ctx EvalContext) (*Graph, error)

GraphNodeDynamicExpandable

func (*NodePlannableResource) Execute added in v0.14.0

func (n *NodePlannableResource) Execute(ctx EvalContext, op walkOperation) error

GraphNodeExecutable

func (*NodePlannableResource) ModifyCreateBeforeDestroy added in v0.12.0

func (n *NodePlannableResource) ModifyCreateBeforeDestroy(v bool) error

GraphNodeDestroyerCBD

func (*NodePlannableResource) ModuleInstance added in v0.13.0

func (n *NodePlannableResource) ModuleInstance() addrs.ModuleInstance

GraphNodeModuleInstance

func (*NodePlannableResource) Name added in v0.13.0

func (n *NodePlannableResource) Name() string

func (*NodePlannableResource) Path added in v0.13.0

type NodePlannableResourceInstance added in v0.7.10

type NodePlannableResourceInstance struct {
	*NodeAbstractResourceInstance
	ForceCreateBeforeDestroy bool
	// contains filtered or unexported fields
}

NodePlannableResourceInstance represents a _single_ resource instance that is plannable. This means this represents a single count index, for example.

func (*NodePlannableResourceInstance) Execute added in v0.14.0

func (n *NodePlannableResourceInstance) Execute(ctx EvalContext, op walkOperation) error

GraphNodeEvalable

type NodePlannableResourceInstanceOrphan added in v0.12.0

type NodePlannableResourceInstanceOrphan struct {
	*NodeAbstractResourceInstance
	// contains filtered or unexported fields
}

NodePlannableResourceInstanceOrphan represents a resource that is "applyable": it is ready to be applied and is represented by a diff.

func (*NodePlannableResourceInstanceOrphan) Execute added in v0.14.0

func (n *NodePlannableResourceInstanceOrphan) Execute(ctx EvalContext, op walkOperation) error

GraphNodeExecutable

func (*NodePlannableResourceInstanceOrphan) Name added in v0.12.0

type NodeProvisioner added in v0.9.0

type NodeProvisioner struct {
	NameValue string
	PathValue addrs.ModuleInstance
}

NodeProvisioner represents a provider that has no associated operations. It registers all the common interfaces across operations for providers.

func (*NodeProvisioner) Execute added in v0.14.0

func (n *NodeProvisioner) Execute(ctx EvalContext, op walkOperation) error

GraphNodeExecutable impl.

func (*NodeProvisioner) Name added in v0.9.0

func (n *NodeProvisioner) Name() string

func (*NodeProvisioner) Path added in v0.9.0

GraphNodeModuleInstance

func (*NodeProvisioner) ProvisionerName added in v0.9.0

func (n *NodeProvisioner) ProvisionerName() string

GraphNodeProvisioner

type NodeRootVariable added in v0.7.8

type NodeRootVariable struct {
	Addr   addrs.InputVariable
	Config *configs.Variable
}

NodeRootVariable represents a root variable input.

func (*NodeRootVariable) DotNode added in v0.12.0

func (n *NodeRootVariable) DotNode(name string, opts *dag.DotOpts) *dag.DotNode

dag.GraphNodeDotter impl.

func (*NodeRootVariable) Execute added in v0.14.0

func (n *NodeRootVariable) Execute(ctx EvalContext, op walkOperation) error

GraphNodeExecutable

func (*NodeRootVariable) ModulePath added in v0.13.0

func (n *NodeRootVariable) ModulePath() addrs.Module

func (*NodeRootVariable) Name added in v0.7.8

func (n *NodeRootVariable) Name() string

func (*NodeRootVariable) Path added in v0.12.0

GraphNodeModuleInstance

func (*NodeRootVariable) ReferenceableAddrs added in v0.12.0

func (n *NodeRootVariable) ReferenceableAddrs() []addrs.Referenceable

GraphNodeReferenceable

type NodeValidatableResource added in v0.9.0

type NodeValidatableResource struct {
	*NodeAbstractResource
}

NodeValidatableResource represents a resource that is used for validation only.

func (*NodeValidatableResource) Execute added in v0.14.0

func (n *NodeValidatableResource) Execute(ctx EvalContext, op walkOperation) error

GraphNodeEvalable

func (*NodeValidatableResource) Path added in v0.13.0

type NullGraphWalker added in v0.4.0

type NullGraphWalker struct{}

NullGraphWalker is a GraphWalker implementation that does nothing. This can be embedded within other GraphWalker implementations for easily implementing all the required functions.

func (NullGraphWalker) EnterPath added in v0.5.0

func (NullGraphWalker) EvalContext added in v0.13.0

func (NullGraphWalker) EvalContext() EvalContext

func (NullGraphWalker) Execute added in v0.14.0

func (NullGraphWalker) ExitPath added in v0.5.0

type OrphanOutputTransformer added in v0.7.8

type OrphanOutputTransformer struct {
	Config *configs.Config // Root of config tree
	State  *states.State   // State is the root state
}

OrphanOutputTransformer finds the outputs that aren't present in the given config that are in the state and adds them to the graph for deletion.

func (*OrphanOutputTransformer) Transform added in v0.7.8

func (t *OrphanOutputTransformer) Transform(g *Graph) error

type OrphanResourceInstanceCountTransformer added in v0.13.0

type OrphanResourceInstanceCountTransformer struct {
	Concrete ConcreteResourceInstanceNodeFunc

	Addr          addrs.AbsResource           // Addr of the resource to look for orphans
	InstanceAddrs []addrs.AbsResourceInstance // Addresses that currently exist in config
	State         *states.State               // Full global state
}

OrphanResourceInstanceCountTransformer is a GraphTransformer that adds orphans for an expanded count to the graph. The determination of this depends on the count argument given.

Orphans are found by comparing the count to what is found in the state. This transform assumes that if an element in the state is within the count bounds given, that it is not an orphan.

func (*OrphanResourceInstanceCountTransformer) Transform added in v0.13.0

type OrphanResourceInstanceTransformer added in v0.12.0

type OrphanResourceInstanceTransformer struct {
	Concrete ConcreteResourceInstanceNodeFunc

	// State is the global state. We require the global state to
	// properly find module orphans at our path.
	State *states.State

	// Config is the root node in the configuration tree. We'll look up
	// the appropriate note in this tree using the path in each node.
	Config *configs.Config
}

OrphanResourceInstanceTransformer is a GraphTransformer that adds orphaned resource instances to the graph. An "orphan" is an instance that is present in the state but belongs to a resource that is no longer present in the configuration.

This is not the transformer that deals with "count orphans" (instances that are no longer covered by a resource's "count" or "for_each" setting); that's handled instead by OrphanResourceCountTransformer.

func (*OrphanResourceInstanceTransformer) Transform added in v0.12.0

type OutputState added in v0.7.0

type OutputState struct {
	// Sensitive describes whether the output is considered sensitive,
	// which may lead to masking the value on screen in some cases.
	Sensitive bool `json:"sensitive"`
	// Type describes the structure of Value. Valid values are "string",
	// "map" and "list"
	Type string `json:"type"`
	// Value contains the value of the output, in the structure described
	// by the Type field.
	Value interface{} `json:"value"`
	// contains filtered or unexported fields
}

OutputState is used to track the state relevant to a single output.

func (*OutputState) Equal added in v0.7.0

func (s *OutputState) Equal(other *OutputState) bool

Equal compares two OutputState structures for equality. nil values are considered equal.

func (*OutputState) Lock added in v0.7.3

func (s *OutputState) Lock()

func (*OutputState) String added in v0.7.0

func (s *OutputState) String() string

func (*OutputState) Unlock added in v0.7.3

func (s *OutputState) Unlock()

type OutputTransformer added in v0.7.8

type OutputTransformer struct {
	Config  *configs.Config
	Changes *plans.Changes

	// if this is a planed destroy, root outputs are still in the configuration
	// so we need to record that we wish to remove them
	Destroy bool
}

OutputTransformer is a GraphTransformer that adds all the outputs in the configuration to the graph.

This is done for the apply graph builder even if dependent nodes aren't changing since there is no downside: the state will be available even if the dependent items aren't changing.

func (*OutputTransformer) Transform added in v0.7.8

func (t *OutputTransformer) Transform(g *Graph) error

type ParentProviderTransformer added in v0.7.8

type ParentProviderTransformer struct{}

ParentProviderTransformer connects provider nodes to their parents.

This works by finding nodes that are both GraphNodeProviders and GraphNodeModuleInstance. It then connects the providers to their parent path. The parent provider is always at the root level.

func (*ParentProviderTransformer) Transform added in v0.7.8

func (t *ParentProviderTransformer) Transform(g *Graph) error

type Plan

type Plan struct {
	// Diff describes the resource actions that must be taken when this
	// plan is applied.
	Diff *Diff

	// Config represents the entire configuration that was present when this
	// plan was created.
	Config *configs.Config

	// State is the Terraform state that was current when this plan was
	// created.
	//
	// It is not allowed to apply a plan that has a stale state, since its
	// diff could be outdated.
	State *State

	// Vars retains the variables that were set when creating the plan, so
	// that the same variables can be applied during apply.
	Vars map[string]cty.Value

	// Targets, if non-empty, contains a set of resource address strings that
	// identify graph nodes that were selected as targets for plan.
	//
	// When targets are set, any graph node that is not directly targeted or
	// indirectly targeted via dependencies is excluded from the graph.
	Targets []string

	// TerraformVersion is the version of Terraform that was used to create
	// this plan.
	//
	// It is not allowed to apply a plan created with a different version of
	// Terraform, since the other fields of this structure may be interpreted
	// in different ways between versions.
	TerraformVersion string

	// ProviderSHA256s is a map giving the SHA256 hashes of the exact binaries
	// used as plugins for each provider during plan.
	//
	// These must match between plan and apply to ensure that the diff is
	// correctly interpreted, since different provider versions may have
	// different attributes or attribute value constraints.
	ProviderSHA256s map[string][]byte

	// Backend is the backend that this plan should use and store data with.
	Backend *BackendState

	// Destroy indicates that this plan was created for a full destroy operation
	Destroy bool
	// contains filtered or unexported fields
}

Plan represents a single Terraform execution plan, which contains all the information necessary to make an infrastructure change.

A plan has to contain basically the entire state of the world necessary to make a change: the state, diff, config, backend config, etc. This is so that it can run alone without any other data.

func ReadPlan

func ReadPlan(src io.Reader) (*Plan, error)

ReadPlan reads a plan structure out of a reader in the format that was written by WritePlan.

func (*Plan) String

func (p *Plan) String() string

type PlanGraphBuilder added in v0.7.10

type PlanGraphBuilder struct {
	// Config is the configuration tree to build a plan from.
	Config *configs.Config

	// State is the current state
	State *states.State

	// Components is a factory for the plug-in components (providers and
	// provisioners) available for use.
	Components contextComponentFactory

	// Schemas is the repository of schemas we will draw from to analyse
	// the configuration.
	Schemas *Schemas

	// Targets are resources to target
	Targets []addrs.Targetable

	// Validate will do structural validation of the graph.
	Validate bool

	// CustomConcrete can be set to customize the node types created
	// for various parts of the plan. This is useful in order to customize
	// the plan behavior.
	CustomConcrete         bool
	ConcreteProvider       ConcreteProviderNodeFunc
	ConcreteResource       ConcreteResourceNodeFunc
	ConcreteResourceOrphan ConcreteResourceInstanceNodeFunc
	ConcreteModule         ConcreteModuleNodeFunc
	// contains filtered or unexported fields
}

PlanGraphBuilder implements GraphBuilder and is responsible for building a graph for planning (creating a Terraform Diff).

The primary difference between this graph and others:

  • Based on the config since it represents the target state

  • Ignores lifecycle options since no lifecycle events occur here. This simplifies the graph significantly since complex transforms such as create-before-destroy can be completely ignored.

func (*PlanGraphBuilder) Build added in v0.7.10

See GraphBuilder

func (*PlanGraphBuilder) Steps added in v0.7.10

func (b *PlanGraphBuilder) Steps() []GraphTransformer

See GraphBuilder

type PrefixUIInput added in v0.3.0

type PrefixUIInput struct {
	IdPrefix    string
	QueryPrefix string
	UIInput     UIInput
}

PrefixUIInput is an implementation of UIInput that prefixes the ID with a string, allowing queries to be namespaced.

func (*PrefixUIInput) Input added in v0.3.0

func (i *PrefixUIInput) Input(ctx context.Context, opts *InputOpts) (string, error)

type ProviderConfigTransformer added in v0.11.0

type ProviderConfigTransformer struct {
	Providers []string
	Concrete  ConcreteProviderNodeFunc

	// Config is the root node of the configuration tree to add providers from.
	Config *configs.Config
	// contains filtered or unexported fields
}

ProviderConfigTransformer adds all provider nodes from the configuration and attaches the configs.

func (*ProviderConfigTransformer) Transform added in v0.11.0

func (t *ProviderConfigTransformer) Transform(g *Graph) error

type ProviderSchema added in v0.10.8

type ProviderSchema struct {
	Provider      *configschema.Block
	ProviderMeta  *configschema.Block
	ResourceTypes map[string]*configschema.Block
	DataSources   map[string]*configschema.Block

	ResourceTypeSchemaVersions map[string]uint64
}

ProviderSchema represents the schema for a provider's own configuration and the configuration for some or all of its resources and data sources.

The completeness of this structure depends on how it was constructed. When constructed for a configuration, it will generally include only resource types and data sources used by that configuration.

func GetProvider added in v0.14.0

GetProvider returns the providers.Interface and schema for a given provider.

func (*ProviderSchema) SchemaForResourceAddr added in v0.12.0

func (ps *ProviderSchema) SchemaForResourceAddr(addr addrs.Resource) (schema *configschema.Block, version uint64)

SchemaForResourceAddr attempts to find a schema for the mode and type from the given resource address. Returns nil if no such schema is available.

func (*ProviderSchema) SchemaForResourceType added in v0.12.0

func (ps *ProviderSchema) SchemaForResourceType(mode addrs.ResourceMode, typeName string) (schema *configschema.Block, version uint64)

SchemaForResourceType attempts to find a schema for the given mode and type. Returns nil if no such schema is available.

type ProviderSchemaRequest added in v0.10.8

type ProviderSchemaRequest struct {
	ResourceTypes []string
	DataSources   []string
}

ProviderSchemaRequest is used to describe to a ResourceProvider which aspects of schema are required, when calling the GetSchema method.

type ProviderTransformer added in v0.4.0

type ProviderTransformer struct {
	Config *configs.Config
}

ProviderTransformer is a GraphTransformer that maps resources to providers within the graph. This will error if there are any resources that don't map to proper resources.

func (*ProviderTransformer) Transform added in v0.4.0

func (t *ProviderTransformer) Transform(g *Graph) error

type ProvisionerFactory added in v0.12.0

type ProvisionerFactory = provisioners.Factory

ProvisionerFactory is a function type that creates a new instance of a provisioners.Interface.

type ProvisionerTransformer added in v0.4.0

type ProvisionerTransformer struct{}

ProvisionerTransformer is a GraphTransformer that maps resources to provisioners within the graph. This will error if there are any resources that don't map to proper resources.

func (*ProvisionerTransformer) Transform added in v0.4.0

func (t *ProvisionerTransformer) Transform(g *Graph) error

type ProvisionerUIOutput added in v0.3.0

type ProvisionerUIOutput struct {
	InstanceAddr    addrs.AbsResourceInstance
	ProvisionerType string
	Hooks           []Hook
}

ProvisionerUIOutput is an implementation of UIOutput that calls a hook for the output so that the hooks can handle it.

func (*ProvisionerUIOutput) Output added in v0.3.0

func (o *ProvisionerUIOutput) Output(msg string)

type PruneProviderTransformer added in v0.4.0

type PruneProviderTransformer struct{}

PruneProviderTransformer removes any providers that are not actually used by anything, and provider proxies. This avoids the provider being initialized and configured. This both saves resources but also avoids errors since configuration may imply initialization which may require auth.

func (*PruneProviderTransformer) Transform added in v0.4.0

func (t *PruneProviderTransformer) Transform(g *Graph) error

type ReferenceMap added in v0.7.8

type ReferenceMap map[string][]dag.Vertex

ReferenceMap is a structure that can be used to efficiently check for references on a graph, mapping internal reference keys (as produced by the mapKey method) to one or more vertices that are identified by each key.

func NewReferenceMap added in v0.7.8

func NewReferenceMap(vs []dag.Vertex) ReferenceMap

NewReferenceMap is used to create a new reference map for the given set of vertices.

func (ReferenceMap) References added in v0.7.8

func (m ReferenceMap) References(v dag.Vertex) []dag.Vertex

References returns the set of vertices that the given vertex refers to, and any referenced addresses that do not have corresponding vertices.

type ReferenceTransformer added in v0.7.8

type ReferenceTransformer struct{}

ReferenceTransformer is a GraphTransformer that connects all the nodes that reference each other in order to form the proper ordering.

func (*ReferenceTransformer) Transform added in v0.7.8

func (t *ReferenceTransformer) Transform(g *Graph) error

type RemoteState added in v0.3.5

type RemoteState struct {
	// Type controls the client we use for the remote state
	Type string `json:"type"`

	// Config is used to store arbitrary configuration that
	// is type specific
	Config map[string]string `json:"config"`
	// contains filtered or unexported fields
}

RemoteState is used to track the information about a remote state store that we push/pull state to.

func (*RemoteState) Empty added in v0.3.5

func (r *RemoteState) Empty() bool

func (*RemoteState) Equals added in v0.3.5

func (r *RemoteState) Equals(other *RemoteState) bool

func (*RemoteState) Lock added in v0.7.3

func (s *RemoteState) Lock()

func (*RemoteState) Unlock added in v0.7.3

func (s *RemoteState) Unlock()

type RemovedModuleTransformer added in v0.11.0

type RemovedModuleTransformer struct {
	Config *configs.Config // root node in the config tree
	State  *states.State
}

RemovedModuleTransformer implements GraphTransformer to add nodes indicating when a module was removed from the configuration.

func (*RemovedModuleTransformer) Transform added in v0.11.0

func (t *RemovedModuleTransformer) Transform(g *Graph) error

type Resource

type Resource struct {
	// These are all used by the new EvalNode stuff.
	Name       string
	Type       string
	CountIndex int

	// These aren't really used anymore anywhere, but we keep them around
	// since we haven't done a proper cleanup yet.
	Id           string
	Info         *InstanceInfo
	Config       *ResourceConfig
	Dependencies []string
	Diff         *InstanceDiff
	Provider     ResourceProvider
	State        *InstanceState
	Flags        ResourceFlag
}

Resource is a legacy way to identify a particular resource instance.

New code should use addrs.ResourceInstance instead. This is still here only for codepaths that haven't been updated yet.

func NewResource added in v0.12.0

func NewResource(addr addrs.ResourceInstance) *Resource

NewResource constructs a legacy Resource object from an addrs.ResourceInstance value.

This is provided to shim to old codepaths that haven't been updated away from this type yet. Since this old type is not able to represent instances that have string keys, this function will panic if given a resource address that has a string key.

type ResourceAddress added in v0.4.0

type ResourceAddress struct {
	// Addresses a resource falling somewhere in the module path
	// When specified alone, addresses all resources within a module path
	Path []string

	// Addresses a specific resource that occurs in a list
	Index int

	InstanceType    InstanceType
	InstanceTypeSet bool
	Name            string
	Type            string
	Mode            ResourceMode // significant only if InstanceTypeSet
}

ResourceAddress is a way of identifying an individual resource (or, eventually, a subset of resources) within the state. It is used for Targets.

func NewLegacyResourceAddress added in v0.12.0

func NewLegacyResourceAddress(addr addrs.AbsResource) *ResourceAddress

NewLegacyResourceAddress creates a ResourceAddress from a new-style addrs.AbsResource value.

This is provided for shimming purposes so that we can still easily call into older functions that expect the ResourceAddress type.

func NewLegacyResourceInstanceAddress added in v0.12.0

func NewLegacyResourceInstanceAddress(addr addrs.AbsResourceInstance) *ResourceAddress

NewLegacyResourceInstanceAddress creates a ResourceAddress from a new-style addrs.AbsResource value.

This is provided for shimming purposes so that we can still easily call into older functions that expect the ResourceAddress type.

func ParseResourceAddress added in v0.4.0

func ParseResourceAddress(s string) (*ResourceAddress, error)

func ParseResourceAddressForInstanceDiff added in v0.10.0

func ParseResourceAddressForInstanceDiff(path []string, key string) (*ResourceAddress, error)

ParseResourceAddressForInstanceDiff creates a ResourceAddress for a resource name as described in a module diff.

For historical reasons a different addressing format is used in this context. The internal format should not be shown in the UI and instead this function should be used to translate to a ResourceAddress and then, where appropriate, use the String method to produce a canonical resource address string for display in the UI.

The given path slice must be empty (or nil) for the root module, and otherwise consist of a sequence of module names traversing down into the module tree. If a non-nil path is provided, the caller must not modify its underlying array after passing it to this function.

func (*ResourceAddress) AbsResourceInstanceAddr added in v0.12.0

func (addr *ResourceAddress) AbsResourceInstanceAddr() addrs.AbsResourceInstance

AbsResourceInstanceAddr converts the receiver, a legacy resource address, to the new resource address type addrs.AbsResourceInstance.

This method can be used only on an address that has a resource specification. It will panic if called on a module-path-only ResourceAddress. Use method HasResourceSpec to check before calling, in contexts where it is unclear.

addrs.AbsResourceInstance does not represent the "tainted" and "deposed" states, and so if these are present on the receiver then they are discarded.

This is provided for shimming purposes so that we can easily adapt functions that are returning the legacy ResourceAddress type, for situations where the new type is required.

func (*ResourceAddress) Contains added in v0.10.0

func (addr *ResourceAddress) Contains(other *ResourceAddress) bool

Contains returns true if and only if the given node is contained within the receiver.

Containment is defined in terms of the module and resource heirarchy: a resource is contained within its module and any ancestor modules, an indexed resource instance is contained with the unindexed resource, etc.

func (*ResourceAddress) Copy added in v0.6.12

func (r *ResourceAddress) Copy() *ResourceAddress

Copy returns a copy of this ResourceAddress

func (*ResourceAddress) Equals added in v0.4.0

func (addr *ResourceAddress) Equals(raw interface{}) bool

Equals returns true if the receiver matches the given address.

The name of this method is a misnomer, since it doesn't test for exact equality. Instead, it tests that the _specified_ parts of each address match, treating any unspecified parts as wildcards.

See also Contains, which takes a more hierarchical approach to comparing addresses.

func (*ResourceAddress) HasResourceSpec added in v0.10.0

func (r *ResourceAddress) HasResourceSpec() bool

HasResourceSpec returns true if the address has a resource spec, as defined in the documentation:

https://www.terraform.io/docs/internals/resource-addressing.html

In particular, this returns false if the address contains only a module path, thus addressing the entire module.

func (*ResourceAddress) Less added in v0.10.0

func (addr *ResourceAddress) Less(other *ResourceAddress) bool

Less returns true if and only if the receiver should be sorted before the given address when presenting a list of resource addresses to an end-user.

This sort uses lexicographic sorting for most components, but uses numeric sort for indices, thus causing index 10 to sort after index 9, rather than after index 1.

func (*ResourceAddress) MatchesResourceConfig added in v0.12.0

func (r *ResourceAddress) MatchesResourceConfig(path addrs.Module, rc *configs.Resource) bool

MatchesResourceConfig returns true if the receiver matches the given configuration resource within the given _static_ module path. Note that the module path in a resource address is a _dynamic_ module path, and multiple dynamic resource paths may map to a single static path if count and for_each are in use on module calls.

Since resource configuration blocks represent all of the instances of a multi-instance resource, the index of the address (if any) is not considered.

func (*ResourceAddress) ModuleInstanceAddr added in v0.12.0

func (addr *ResourceAddress) ModuleInstanceAddr() addrs.ModuleInstance

ModuleInstanceAddr returns the module path portion of the receiver as a addrs.ModuleInstance value.

func (*ResourceAddress) String added in v0.7.0

func (r *ResourceAddress) String() string

String outputs the address that parses into this address.

func (*ResourceAddress) WholeModuleAddress added in v0.10.0

func (r *ResourceAddress) WholeModuleAddress() *ResourceAddress

WholeModuleAddress returns the resource address that refers to all resources in the same module as the receiver address.

type ResourceAttrDiff

type ResourceAttrDiff struct {
	Old         string      // Old Value
	New         string      // New Value
	NewComputed bool        // True if new value is computed (unknown currently)
	NewRemoved  bool        // True if this attribute is being removed
	NewExtra    interface{} // Extra information for the provider
	RequiresNew bool        // True if change requires new resource
	Sensitive   bool        // True if the data should not be displayed in UI output
	Type        DiffAttrType
}

ResourceAttrDiff is the diff of a single attribute of a resource.

func (*ResourceAttrDiff) Empty added in v0.6.14

func (d *ResourceAttrDiff) Empty() bool

Empty returns true if the diff for this attr is neutral

func (*ResourceAttrDiff) GoString

func (d *ResourceAttrDiff) GoString() string

type ResourceConfig

type ResourceConfig struct {
	ComputedKeys []string
	Raw          map[string]interface{}
	Config       map[string]interface{}
}

ResourceConfig is a legacy type that was formerly used to represent interpolatable configuration blocks. It is now only used to shim to old APIs that still use this type, via NewResourceConfigShimmed.

func NewResourceConfigRaw added in v0.12.7

func NewResourceConfigRaw(raw map[string]interface{}) *ResourceConfig

NewResourceConfigRaw constructs a ResourceConfig whose content is exactly the given value.

The given value may contain hcl2shim.UnknownVariableValue to signal that something is computed, but it must not contain unprocessed interpolation sequences as we might've seen in Terraform v0.11 and prior.

func NewResourceConfigShimmed added in v0.12.0

func NewResourceConfigShimmed(val cty.Value, schema *configschema.Block) *ResourceConfig

NewResourceConfigShimmed wraps a cty.Value of object type in a legacy ResourceConfig object, so that it can be passed to older APIs that expect this wrapping.

The returned ResourceConfig is already interpolated and cannot be re-interpolated. It is, therefore, useful only to functions that expect an already-populated ResourceConfig which they then treat as read-only.

If the given value is not of an object type that conforms to the given schema then this function will panic.

func (*ResourceConfig) CheckSet

func (c *ResourceConfig) CheckSet(keys []string) []error

CheckSet checks that the given list of configuration keys is properly set. If not, errors are returned for each unset key.

This is useful to be called in the Validate method of a ResourceProvider.

func (*ResourceConfig) DeepCopy added in v0.7.5

func (c *ResourceConfig) DeepCopy() *ResourceConfig

DeepCopy performs a deep copy of the configuration. This makes it safe to modify any of the structures that are part of the resource config without affecting the original configuration.

func (*ResourceConfig) Equal added in v0.7.5

func (c *ResourceConfig) Equal(c2 *ResourceConfig) bool

Equal checks the equality of two resource configs.

func (*ResourceConfig) Get

func (c *ResourceConfig) Get(k string) (interface{}, bool)

Get looks up a configuration value by key and returns the value.

The second return value is true if the get was successful. Get will return the raw value if the key is computed, so you should pair this with IsComputed.

func (*ResourceConfig) GetRaw added in v0.5.0

func (c *ResourceConfig) GetRaw(k string) (interface{}, bool)

GetRaw looks up a configuration value by key and returns the value, from the raw, uninterpolated config.

The second return value is true if the get was successful. Get will not succeed if the value is being computed.

func (*ResourceConfig) IsComputed added in v0.3.0

func (c *ResourceConfig) IsComputed(k string) bool

IsComputed returns whether the given key is computed or not.

func (*ResourceConfig) IsSet

func (c *ResourceConfig) IsSet(k string) bool

IsSet checks if the key in the configuration is set. A key is set if it has a value or the value is being computed (is unknown currently).

This function should be used rather than checking the keys of the raw configuration itself, since a key may be omitted from the raw configuration if it is being computed.

type ResourceCountTransformer added in v0.4.0

type ResourceCountTransformer struct {
	Concrete ConcreteResourceInstanceNodeFunc
	Schema   *configschema.Block

	Addr          addrs.ConfigResource
	InstanceAddrs []addrs.AbsResourceInstance
}

ResourceCountTransformer is a GraphTransformer that expands the count out for a specific resource.

This assumes that the count is already interpolated.

func (*ResourceCountTransformer) Transform added in v0.4.0

func (t *ResourceCountTransformer) Transform(g *Graph) error

type ResourceFlag added in v0.3.0

type ResourceFlag byte

ResourceKind specifies what kind of instance we're working with, whether its a primary instance, a tainted instance, or an orphan.

type ResourceMode added in v0.12.7

type ResourceMode int

ResourceMode is deprecated, use addrs.ResourceMode instead. It has been preserved for backwards compatibility.

const (
	ManagedResourceMode ResourceMode = iota
	DataResourceMode
)

func (ResourceMode) String added in v0.12.7

func (i ResourceMode) String() string

type ResourceProvider

type ResourceProvider interface {

	// ProviderSchema returns the config schema for the main provider
	// configuration, as would appear in a "provider" block in the
	// configuration files.
	//
	// Currently not all providers support schema. Callers must therefore
	// first call Resources and DataSources and ensure that at least one
	// resource or data source has the SchemaAvailable flag set.
	GetSchema(*ProviderSchemaRequest) (*ProviderSchema, error)

	// Input was used prior to v0.12 to ask the provider to prompt the user
	// for input to complete the configuration.
	//
	// From v0.12 onwards this method is never called because Terraform Core
	// is able to handle the necessary input logic itself based on the
	// schema returned from GetSchema.
	Input(UIInput, *ResourceConfig) (*ResourceConfig, error)

	// Validate is called once at the beginning with the raw configuration
	// (no interpolation done) and can return a list of warnings and/or
	// errors.
	//
	// This is called once with the provider configuration only. It may not
	// be called at all if no provider configuration is given.
	//
	// This should not assume that any values of the configurations are valid.
	// The primary use case of this call is to check that required keys are
	// set.
	Validate(*ResourceConfig) ([]string, []error)

	// Configure configures the provider itself with the configuration
	// given. This is useful for setting things like access keys.
	//
	// This won't be called at all if no provider configuration is given.
	//
	// Configure returns an error if it occurred.
	Configure(*ResourceConfig) error

	// Resources returns all the available resource types that this provider
	// knows how to manage.
	Resources() []ResourceType

	// Stop is called when the provider should halt any in-flight actions.
	//
	// This can be used to make a nicer Ctrl-C experience for Terraform.
	// Even if this isn't implemented to do anything (just returns nil),
	// Terraform will still cleanly stop after the currently executing
	// graph node is complete. However, this API can be used to make more
	// efficient halts.
	//
	// Stop doesn't have to and shouldn't block waiting for in-flight actions
	// to complete. It should take any action it wants and return immediately
	// acknowledging it has received the stop request. Terraform core will
	// automatically not make any further API calls to the provider soon
	// after Stop is called (technically exactly once the currently executing
	// graph nodes are complete).
	//
	// The error returned, if non-nil, is assumed to mean that signaling the
	// stop somehow failed and that the user should expect potentially waiting
	// a longer period of time.
	Stop() error

	// ValidateResource is called once at the beginning with the raw
	// configuration (no interpolation done) and can return a list of warnings
	// and/or errors.
	//
	// This is called once per resource.
	//
	// This should not assume any of the values in the resource configuration
	// are valid since it is possible they have to be interpolated still.
	// The primary use case of this call is to check that the required keys
	// are set and that the general structure is correct.
	ValidateResource(string, *ResourceConfig) ([]string, []error)

	// Apply applies a diff to a specific resource and returns the new
	// resource state along with an error.
	//
	// If the resource state given has an empty ID, then a new resource
	// is expected to be created.
	Apply(
		*InstanceInfo,
		*InstanceState,
		*InstanceDiff) (*InstanceState, error)

	// Diff diffs a resource versus a desired state and returns
	// a diff.
	Diff(
		*InstanceInfo,
		*InstanceState,
		*ResourceConfig) (*InstanceDiff, error)

	// Refresh refreshes a resource and updates all of its attributes
	// with the latest information.
	Refresh(*InstanceInfo, *InstanceState) (*InstanceState, error)

	// ImportState requests that the given resource be imported.
	//
	// The returned InstanceState only requires ID be set. Importing
	// will always call Refresh after the state to complete it.
	//
	// IMPORTANT: InstanceState doesn't have the resource type attached
	// to it. A type must be specified on the state via the Ephemeral
	// field on the state.
	//
	// This function can return multiple states. Normally, an import
	// will map 1:1 to a physical resource. However, some resources map
	// to multiple. For example, an AWS security group may contain many rules.
	// Each rule is represented by a separate resource in Terraform,
	// therefore multiple states are returned.
	ImportState(*InstanceInfo, string) ([]*InstanceState, error)

	// ValidateDataSource is called once at the beginning with the raw
	// configuration (no interpolation done) and can return a list of warnings
	// and/or errors.
	//
	// This is called once per data source instance.
	//
	// This should not assume any of the values in the resource configuration
	// are valid since it is possible they have to be interpolated still.
	// The primary use case of this call is to check that the required keys
	// are set and that the general structure is correct.
	ValidateDataSource(string, *ResourceConfig) ([]string, []error)

	// DataSources returns all of the available data sources that this
	// provider implements.
	DataSources() []DataSource

	// ReadDataDiff produces a diff that represents the state that will
	// be produced when the given data source is read using a later call
	// to ReadDataApply.
	ReadDataDiff(*InstanceInfo, *ResourceConfig) (*InstanceDiff, error)

	// ReadDataApply initializes a data instance using the configuration
	// in a diff produced by ReadDataDiff.
	ReadDataApply(*InstanceInfo, *InstanceDiff) (*InstanceState, error)
}

ResourceProvider is a legacy interface for providers.

This is retained only for compatibility with legacy code. The current interface for providers is providers.Interface, in the sibling directory named "providers".

type ResourceProviderCloser added in v0.6.0

type ResourceProviderCloser interface {
	Close() error
}

ResourceProviderCloser is an interface that providers that can close connections that aren't needed anymore must implement.

type ResourceProviderFactory

type ResourceProviderFactory func() (ResourceProvider, error)

ResourceProviderFactory is a function type that creates a new instance of a resource provider.

func ResourceProviderFactoryFixed

func ResourceProviderFactoryFixed(p ResourceProvider) ResourceProviderFactory

ResourceProviderFactoryFixed is a helper that creates a ResourceProviderFactory that just returns some fixed provider.

type ResourceProvisioner

type ResourceProvisioner interface {
	// GetConfigSchema returns the schema for the provisioner type's main
	// configuration block. This is called prior to Validate to enable some
	// basic structural validation to be performed automatically and to allow
	// the configuration to be properly extracted from potentially-ambiguous
	// configuration file formats.
	GetConfigSchema() (*configschema.Block, error)

	// Validate is called once at the beginning with the raw
	// configuration (no interpolation done) and can return a list of warnings
	// and/or errors.
	//
	// This is called once per resource.
	//
	// This should not assume any of the values in the resource configuration
	// are valid since it is possible they have to be interpolated still.
	// The primary use case of this call is to check that the required keys
	// are set and that the general structure is correct.
	Validate(*ResourceConfig) ([]string, []error)

	// Apply runs the provisioner on a specific resource and returns an error.
	// Instead of a diff, the ResourceConfig is provided since provisioners
	// only run after a resource has been newly created.
	Apply(UIOutput, *InstanceState, *ResourceConfig) error

	// Stop is called when the provisioner should halt any in-flight actions.
	//
	// This can be used to make a nicer Ctrl-C experience for Terraform.
	// Even if this isn't implemented to do anything (just returns nil),
	// Terraform will still cleanly stop after the currently executing
	// graph node is complete. However, this API can be used to make more
	// efficient halts.
	//
	// Stop doesn't have to and shouldn't block waiting for in-flight actions
	// to complete. It should take any action it wants and return immediately
	// acknowledging it has received the stop request. Terraform core will
	// automatically not make any further API calls to the provider soon
	// after Stop is called (technically exactly once the currently executing
	// graph nodes are complete).
	//
	// The error returned, if non-nil, is assumed to mean that signaling the
	// stop somehow failed and that the user should expect potentially waiting
	// a longer period of time.
	Stop() error
}

ResourceProvisioner is an interface that must be implemented by any resource provisioner: the thing that initializes resources in a Terraform configuration.

type ResourceProvisionerCloser added in v0.6.0

type ResourceProvisionerCloser interface {
	Close() error
}

ResourceProvisionerCloser is an interface that provisioners that can close connections that aren't needed anymore must implement.

type ResourceProvisionerFactory

type ResourceProvisionerFactory func() (ResourceProvisioner, error)

ResourceProvisionerFactory is a function type that creates a new instance of a resource provisioner.

type ResourceState

type ResourceState struct {
	// This is filled in and managed by Terraform, and is the resource
	// type itself such as "mycloud_instance". If a resource provider sets
	// this value, it won't be persisted.
	Type string `json:"type"`

	// Dependencies are a list of things that this resource relies on
	// existing to remain intact. For example: an AWS instance might
	// depend on a subnet (which itself might depend on a VPC, and so
	// on).
	//
	// Terraform uses this information to build valid destruction
	// orders and to warn the user if they're destroying a resource that
	// another resource depends on.
	//
	// Things can be put into this list that may not be managed by
	// Terraform. If Terraform doesn't find a matching ID in the
	// overall state, then it assumes it isn't managed and doesn't
	// worry about it.
	Dependencies []string `json:"depends_on"`

	// Primary is the current active instance for this resource.
	// It can be replaced but only after a successful creation.
	// This is the instances on which providers will act.
	Primary *InstanceState `json:"primary"`

	// Deposed is used in the mechanics of CreateBeforeDestroy: the existing
	// Primary is Deposed to get it out of the way for the replacement Primary to
	// be created by Apply. If the replacement Primary creates successfully, the
	// Deposed instance is cleaned up.
	//
	// If there were problems creating the replacement Primary, the Deposed
	// instance and the (now tainted) replacement Primary will be swapped so the
	// tainted replacement will be cleaned up instead.
	//
	// An instance will remain in the Deposed list until it is successfully
	// destroyed and purged.
	Deposed []*InstanceState `json:"deposed"`

	// Provider is used when a resource is connected to a provider with an alias.
	// If this string is empty, the resource is connected to the default provider,
	// e.g. "aws_instance" goes with the "aws" provider.
	// If the resource block contained a "provider" key, that value will be set here.
	Provider string `json:"provider"`
	// contains filtered or unexported fields
}

ResourceState holds the state of a resource that is used so that a provider can find and manage an existing resource as well as for storing attributes that are used to populate variables of child resources.

Attributes has attributes about the created resource that are queryable in interpolation: "${type.id.attr}"

Extra is just extra data that a provider can return that we store for later, but is not exposed in any way to the user.

func (*ResourceState) Equal added in v0.4.0

func (s *ResourceState) Equal(other *ResourceState) bool

Equal tests whether two ResourceStates are equal.

func (*ResourceState) Lock added in v0.7.3

func (s *ResourceState) Lock()

func (*ResourceState) ProviderAddr added in v0.12.0

func (s *ResourceState) ProviderAddr() (addrs.AbsProviderConfig, error)

ProviderAddr returns the provider address for the receiver, by parsing the string representation saved in state. An error can be returned if the value in state is corrupt.

func (*ResourceState) String added in v0.3.0

func (s *ResourceState) String() string

func (*ResourceState) Taint added in v0.4.0

func (s *ResourceState) Taint()

Taint marks a resource as tainted.

func (*ResourceState) Unlock added in v0.7.3

func (s *ResourceState) Unlock()

func (*ResourceState) Untaint added in v0.6.13

func (s *ResourceState) Untaint()

Untaint unmarks a resource as tainted.

type ResourceStateKey added in v0.6.10

type ResourceStateKey struct {
	Name  string
	Type  string
	Mode  ResourceMode
	Index int
}

ResourceStateKey is a structured representation of the key used for the ModuleState.Resources mapping

func ParseResourceStateKey added in v0.6.10

func ParseResourceStateKey(k string) (*ResourceStateKey, error)

ParseResourceStateKey accepts a key in the format used by ModuleState.Resources and returns a resource name and resource index. In the state, a resource has the format "type.name.index" or "type.name". In the latter case, the index is returned as -1.

func (*ResourceStateKey) Equal added in v0.6.10

func (rsk *ResourceStateKey) Equal(other *ResourceStateKey) bool

Equal determines whether two ResourceStateKeys are the same

func (*ResourceStateKey) String added in v0.6.10

func (rsk *ResourceStateKey) String() string

type ResourceType

type ResourceType struct {
	Name       string // Name of the resource, example "instance" (no provider prefix)
	Importable bool   // Whether this resource supports importing

	// SchemaAvailable is set if the provider supports the ProviderSchema,
	// ResourceTypeSchema and DataSourceSchema methods. Although it is
	// included on each resource type, it's actually a provider-wide setting
	// that's smuggled here only because that avoids a breaking change to
	// the plugin protocol.
	SchemaAvailable bool
}

ResourceType is a type of resource that a resource provider can manage.

type RootTransformer added in v0.4.0

type RootTransformer struct{}

RootTransformer is a GraphTransformer that adds a root to the graph.

func (*RootTransformer) Transform added in v0.4.0

func (t *RootTransformer) Transform(g *Graph) error

type RootVariableTransformer added in v0.7.8

type RootVariableTransformer struct {
	Config *configs.Config
}

RootVariableTransformer is a GraphTransformer that adds all the root variables to the graph.

Root variables are currently no-ops but they must be added to the graph since downstream things that depend on them must be able to reach them.

func (*RootVariableTransformer) Transform added in v0.7.8

func (t *RootVariableTransformer) Transform(g *Graph) error

type Schemas added in v0.10.8

type Schemas struct {
	Providers    map[addrs.Provider]*ProviderSchema
	Provisioners map[string]*configschema.Block
}

Schemas is a container for various kinds of schema that Terraform needs during processing.

func LoadSchemas added in v0.12.0

func LoadSchemas(config *configs.Config, state *states.State, components contextComponentFactory) (*Schemas, error)

LoadSchemas searches the given configuration, state and plan (any of which may be nil) for constructs that have an associated schema, requests the necessary schemas from the given component factory (which must _not_ be nil), and returns a single object representing all of the necessary schemas.

If an error is returned, it may be a wrapped tfdiags.Diagnostics describing errors across multiple separate objects. Errors here will usually indicate either misbehavior on the part of one of the providers or of the provider protocol itself. When returned with errors, the returned schemas object is still valid but may be incomplete.

func (*Schemas) ProviderConfig added in v0.12.0

func (ss *Schemas) ProviderConfig(provider addrs.Provider) *configschema.Block

ProviderConfig returns the schema for the provider configuration of the given provider type, or nil if no such schema is available.

func (*Schemas) ProviderSchema added in v0.12.0

func (ss *Schemas) ProviderSchema(provider addrs.Provider) *ProviderSchema

ProviderSchema returns the entire ProviderSchema object that was produced by the plugin for the given provider, or nil if no such schema is available.

It's usually better to go use the more precise methods offered by type Schemas to handle this detail automatically.

func (*Schemas) ProvisionerConfig added in v0.12.0

func (ss *Schemas) ProvisionerConfig(name string) *configschema.Block

ProvisionerConfig returns the schema for the configuration of a given provisioner, or nil of no such schema is available.

func (*Schemas) ResourceTypeConfig added in v0.12.0

func (ss *Schemas) ResourceTypeConfig(provider addrs.Provider, resourceMode addrs.ResourceMode, resourceType string) (block *configschema.Block, schemaVersion uint64)

ResourceTypeConfig returns the schema for the configuration of a given resource type belonging to a given provider type, or nil of no such schema is available.

In many cases the provider type is inferrable from the resource type name, but this is not always true because users can override the provider for a resource using the "provider" meta-argument. Therefore it's important to always pass the correct provider name, even though it many cases it feels redundant.

type Semaphore added in v0.3.1

type Semaphore chan struct{}

Semaphore is a wrapper around a channel to provide utility methods to clarify that we are treating the channel as a semaphore

func NewSemaphore added in v0.3.1

func NewSemaphore(n int) Semaphore

NewSemaphore creates a semaphore that allows up to a given limit of simultaneous acquisitions

func (Semaphore) Acquire added in v0.3.1

func (s Semaphore) Acquire()

Acquire is used to acquire an available slot. Blocks until available.

func (Semaphore) Release added in v0.3.1

func (s Semaphore) Release()

Release is used to return a slot. Acquire must be called as a pre-condition.

func (Semaphore) TryAcquire added in v0.3.1

func (s Semaphore) TryAcquire() bool

TryAcquire is used to do a non-blocking acquire. Returns a bool indicating success

type State

type State struct {
	// 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 *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 *BackendState `json:"backend,omitempty"`

	// Modules contains all the modules in a breadth-first order
	Modules []*ModuleState `json:"modules"`
	// contains filtered or unexported fields
}

State keeps track of a snapshot state-of-the-world that Terraform can use to keep track of what real world resources it is actually managing.

func NewState added in v0.3.5

func NewState() *State

NewState is used to initialize a blank state

func ReadState

func ReadState(src io.Reader) (*State, error)

ReadState reads a state structure out of a reader in the format that was written by WriteState.

func ReadStateV2 added in v0.7.0

func ReadStateV2(jsonBytes []byte) (*State, error)

func ReadStateV3 added in v0.7.0

func ReadStateV3(jsonBytes []byte) (*State, error)

func (*State) AddModule added in v0.3.0

func (s *State) AddModule(path addrs.ModuleInstance) *ModuleState

AddModule adds the module with the given path to the state.

This should be the preferred method to add module states since it allows us to optimize lookups later as well as control sorting.

func (*State) AddModuleState added in v0.7.1

func (s *State) AddModuleState(mod *ModuleState)

AddModuleState insert this module state and override any existing ModuleState

func (*State) Children added in v0.3.0

func (s *State) Children(path []string) []*ModuleState

Children returns the ModuleStates that are direct children of the given path. If the path is "root", for example, then children returned might be "root.child", but not "root.child.grandchild".

func (*State) CompareAges added in v0.7.0

func (s *State) CompareAges(other *State) (StateAgeComparison, error)

CompareAges compares one state with another for which is "older".

This is a simple check using the state's serial, and is thus only as reliable as the serial itself. In the normal case, only one state exists for a given combination of lineage/serial, but Terraform does not guarantee this and so the result of this method should be used with care.

Returns an integer that is negative if the receiver is older than the argument, positive if the converse, and zero if they are equal. An error is returned if the two states are not of the same lineage, in which case the integer returned has no meaning.

func (*State) DeepCopy added in v0.4.0

func (s *State) DeepCopy() *State

DeepCopy performs a deep copy of the state structure and returns a new structure.

func (*State) Empty added in v0.4.0

func (s *State) Empty() bool

Empty returns true if the state is empty.

func (*State) EnsureHasLineage added in v0.7.0

func (s *State) EnsureHasLineage()

func (*State) Equal added in v0.4.0

func (s *State) Equal(other *State) bool

Equal tests if one state is equal to another.

func (*State) FromFutureTerraform added in v0.7.0

func (s *State) FromFutureTerraform() bool

FromFutureTerraform checks if this state was written by a Terraform version from the future.

func (*State) HasResources added in v0.7.6

func (s *State) HasResources() bool

HasResources returns true if the state contains any resources.

This is similar to !s.Empty, but returns true also in the case where the state has modules but all of them are devoid of resources.

func (*State) Init added in v0.7.1

func (s *State) Init()

func (*State) IsRemote added in v0.4.0

func (s *State) IsRemote() bool

IsRemote returns true if State represents a state that exists and is remote.

func (*State) Lock added in v0.7.3

func (s *State) Lock()

func (*State) MarshalEqual added in v0.10.0

func (s *State) MarshalEqual(other *State) bool

MarshalEqual is similar to Equal but provides a stronger definition of "equal", where two states are equal if and only if their serialized form is byte-for-byte identical.

This is primarily useful for callers that are trying to save snapshots of state to persistent storage, allowing them to detect when a new snapshot must be taken.

Note that the serial number and lineage are included in the serialized form, so it's the caller's responsibility to properly manage these attributes so that this method is only called on two states that have the same serial and lineage, unless detecting such differences is desired.

func (*State) ModuleByPath added in v0.3.0

func (s *State) ModuleByPath(path addrs.ModuleInstance) *ModuleState

ModuleByPath is used to lookup the module state for the given path. This should be the preferred lookup mechanism as it allows for future lookup optimizations.

func (*State) Remove added in v0.7.0

func (s *State) Remove(addr ...string) error

Remove removes the item in the state at the given address, returning any errors that may have occurred.

If the address references a module state or resource, it will delete all children as well. To check what will be deleted, use a StateFilter first.

func (*State) RootModule added in v0.3.0

func (s *State) RootModule() *ModuleState

RootModule returns the ModuleState for the root module

func (*State) SameLineage added in v0.7.0

func (s *State) SameLineage(other *State) bool

SameLineage returns true only if the state given in argument belongs to the same "lineage" of states as the receiver.

func (*State) String

func (s *State) String() string

func (*State) Unlock added in v0.7.3

func (s *State) Unlock()

func (*State) Validate added in v0.7.3

func (s *State) Validate() error

Validate validates the integrity of this state file.

Certain properties of the statefile are expected by Terraform in order to behave properly. The core of Terraform will assume that once it receives a State structure that it has been validated. This validation check should be called to ensure that.

If this returns an error, then the user should be notified. The error response will include detailed information on the nature of the error.

type StateAgeComparison added in v0.7.0

type StateAgeComparison int
const (
	StateAgeEqual         StateAgeComparison = 0
	StateAgeReceiverNewer StateAgeComparison = 1
	StateAgeReceiverOlder StateAgeComparison = -1
)

type StateFilter added in v0.7.0

type StateFilter struct {
	State *State
}

StateFilter is responsible for filtering and searching a state.

This is a separate struct from State rather than a method on State because StateFilter might create sidecar data structures to optimize filtering on the state.

If you change the State, the filter created is invalid and either Reset should be called or a new one should be allocated. StateFilter will not watch State for changes and do this for you. If you filter after changing the State without calling Reset, the behavior is not defined.

func (*StateFilter) Filter added in v0.7.0

func (f *StateFilter) Filter(fs ...string) ([]*StateFilterResult, error)

Filter takes the addresses specified by fs and finds all the matches. The values of fs are resource addressing syntax that can be parsed by ParseResourceAddress.

type StateFilterResult added in v0.7.0

type StateFilterResult struct {
	// Module path of the result
	Path []string

	// Address is the address that can be used to reference this exact result.
	Address string

	// Parent, if non-nil, is a parent of this result. For instances, the
	// parent would be a resource. For resources, the parent would be
	// a module. For modules, this is currently nil.
	Parent *StateFilterResult

	// Value is the actual value. This must be type switched on. It can be
	// any data structures that `State` can hold: `ModuleState`,
	// `ResourceState`, `InstanceState`.
	Value interface{}
}

StateFilterResult is a single result from a filter operation. Filter can match multiple things within a state (module, resource, instance, etc.) and this unifies that.

func (*StateFilterResult) String added in v0.7.0

func (r *StateFilterResult) String() string

type StateFilterResultSlice added in v0.7.0

type StateFilterResultSlice []*StateFilterResult

StateFilterResultSlice is a slice of results that implements sort.Interface. The sorting goal is what is most appealing to human output.

func (StateFilterResultSlice) Len added in v0.7.0

func (s StateFilterResultSlice) Len() int

func (StateFilterResultSlice) Less added in v0.7.0

func (s StateFilterResultSlice) Less(i, j int) bool

func (StateFilterResultSlice) Swap added in v0.7.0

func (s StateFilterResultSlice) Swap(i, j int)

type StateTransformer added in v0.7.8

type StateTransformer struct {
	// ConcreteCurrent and ConcreteDeposed are used to specialize the abstract
	// resource instance nodes that this transformer will create.
	//
	// If either of these is nil, the objects of that type will be skipped and
	// not added to the graph at all. It doesn't make sense to use this
	// transformer without setting at least one of these, since that would
	// skip everything and thus be a no-op.
	ConcreteCurrent ConcreteResourceInstanceNodeFunc
	ConcreteDeposed ConcreteResourceInstanceDeposedNodeFunc

	State *states.State
}

StateTransformer is a GraphTransformer that adds the elements of the state to the graph.

This transform is used for example by the DestroyPlanGraphBuilder to ensure that only resources that are in the state are represented in the graph.

func (*StateTransformer) Transform added in v0.7.8

func (t *StateTransformer) Transform(g *Graph) error

type TargetsTransformer added in v0.4.0

type TargetsTransformer struct {
	// List of targeted resource names specified by the user
	Targets []addrs.Targetable
}

TargetsTransformer is a GraphTransformer that, when the user specifies a list of resources to target, limits the graph to only those resources and their dependencies.

func (*TargetsTransformer) Transform added in v0.4.0

func (t *TargetsTransformer) Transform(g *Graph) error

type TransitiveReductionTransformer added in v0.4.0

type TransitiveReductionTransformer struct{}

TransitiveReductionTransformer is a GraphTransformer that performs finds the transitive reduction of the graph. For a definition of transitive reduction, see Wikipedia.

func (*TransitiveReductionTransformer) Transform added in v0.4.0

func (t *TransitiveReductionTransformer) Transform(g *Graph) error

type UIInput added in v0.3.0

type UIInput interface {
	Input(context.Context, *InputOpts) (string, error)
}

UIInput is the interface that must be implemented to ask for input from this user. This should forward the request to wherever the user inputs things to ask for values.

type UIOutput added in v0.3.0

type UIOutput interface {
	Output(string)
}

UIOutput is the interface that must be implemented to output data to the end user.

type ValueSourceType added in v0.12.0

type ValueSourceType rune

ValueSourceType describes what broad category of source location provided a particular value.

const (
	// ValueFromUnknown is the zero value of ValueSourceType and is not valid.
	ValueFromUnknown ValueSourceType = 0

	// ValueFromConfig indicates that a value came from a .tf or .tf.json file,
	// e.g. the default value defined for a variable.
	ValueFromConfig ValueSourceType = 'C'

	// ValueFromAutoFile indicates that a value came from a "values file", like
	// a .tfvars file, that was implicitly loaded by naming convention.
	ValueFromAutoFile ValueSourceType = 'F'

	// ValueFromNamedFile indicates that a value came from a named "values file",
	// like a .tfvars file, that was passed explicitly on the command line (e.g.
	// -var-file=foo.tfvars).
	ValueFromNamedFile ValueSourceType = 'N'

	// ValueFromCLIArg indicates that the value was provided directly in
	// a CLI argument. The name of this argument is not recorded and so it must
	// be inferred from context.
	ValueFromCLIArg ValueSourceType = 'A'

	// ValueFromEnvVar indicates that the value was provided via an environment
	// variable. The name of the variable is not recorded and so it must be
	// inferred from context.
	ValueFromEnvVar ValueSourceType = 'E'

	// ValueFromInput indicates that the value was provided at an interactive
	// input prompt.
	ValueFromInput ValueSourceType = 'I'

	// ValueFromPlan indicates that the value was retrieved from a stored plan.
	ValueFromPlan ValueSourceType = 'P'

	// ValueFromCaller indicates that the value was explicitly overridden by
	// a caller to Context.SetVariable after the context was constructed.
	ValueFromCaller ValueSourceType = 'S'
)

func (ValueSourceType) GoString added in v0.12.0

func (v ValueSourceType) GoString() string

func (ValueSourceType) String added in v0.12.0

func (i ValueSourceType) String() string

type VertexTransformer added in v0.4.0

type VertexTransformer struct {
	Transforms []GraphVertexTransformer
}

VertexTransformer is a GraphTransformer that transforms vertices using the GraphVertexTransformers. The Transforms are run in sequential order. If a transform replaces a vertex then the next transform will see the new vertex.

func (*VertexTransformer) Transform added in v0.4.0

func (t *VertexTransformer) Transform(g *Graph) error

Notes

Bugs

  • we're not validating provider_meta blocks on EvalValidate right now because the ProviderAddr for the resource isn't available on the EvalValidate struct.

Source Files

Jump to

Keyboard shortcuts

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