Documentation
¶
Overview ¶
Package execution applies provider-evaluated hooks and extra arguments to Terraform commands.
A configuration provider (for example the native Terragrunt plugin) evaluates hooks and extra arguments but never runs them. The host owns execution: it matches them against the command being run, runs hooks with the invocation's environment, working directory, cancellation, and I/O, and surfaces failures with their exit codes. The rules follow Terragrunt's own: a command is matched by name, `apply -destroy` counts as `destroy`, before hooks gate the command, after hooks need run_on_error to follow a failure, and error hooks match on the failure text.
Index ¶
- func CheckRequiredVarFiles(items []schema.ComponentExtraArguments, command, workingDirectory string) error
- func CommandName(command string, flags []string) string
- func Run(ctx context.Context, config *schema.ComponentExecution, command string, ...) error
- func Validate(config *schema.ComponentExecution) error
- type ArgumentsRequest
- type ArgumentsResult
- type HookKind
- type Output
- type Runner
- type TextOutput
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckRequiredVarFiles ¶
func CheckRequiredVarFiles(items []schema.ComponentExtraArguments, command, workingDirectory string) error
CheckRequiredVarFiles verifies the required variable files of every block that lists the command, without building any arguments. It lets a caller reject a missing file before implicit init or workspace subprocesses, and their hooks, run for that command.
func CommandName ¶
CommandName returns the name that hooks and extra arguments match against. It is "destroy" for `destroy` and for `apply` with the destroy flag set, and the command itself otherwise, so `plan -destroy` still matches "plan".
func Run ¶
func Run(ctx context.Context, config *schema.ComponentExecution, command string, runner Runner, action func() (Output, error)) error
Run executes the command lifecycle: before hooks, the action, after hooks, then error hooks.
A failing before hook stops the action. After hooks run after a failure only when they set run_on_error. Error hooks run when any earlier phase failed and an on_errors expression matches that phase's error or output. Cancellation stops every remaining hook. The action's error is returned unchanged when nothing else failed.
func Validate ¶
func Validate(config *schema.ComponentExecution) error
Validate rejects hooks the host cannot run, so a malformed provider response fails before any command starts instead of silently skipping a hook.
Types ¶
type ArgumentsRequest ¶
type ArgumentsRequest struct {
// Command is the matching name from CommandName.
Command string
// Args is the full argument vector, starting with the command.
Args []string
// InsertAt is the index after the command and its subcommands where extra arguments go.
InsertAt int
// PlanFileArgument reports that the last argument is a saved plan. Terraform rejects -var
// options beside a saved plan, so they are dropped.
PlanFileArgument bool
// WorkingDirectory resolves relative variable file paths. Terraform runs there.
WorkingDirectory string
}
ArgumentsRequest describes one Terraform invocation for ApplyExtraArguments.
type ArgumentsResult ¶
type ArgumentsResult struct {
Args []string
// Environment holds KEY=value entries sorted by key. Later blocks override earlier ones.
Environment []string
}
ArgumentsResult is the rewritten invocation.
func ApplyExtraArguments ¶
func ApplyExtraArguments(items []schema.ComponentExtraArguments, request *ArgumentsRequest) (ArgumentsResult, error)
ApplyExtraArguments adds the arguments, variable files, and environment of every block that lists the command, in declaration order. The input arguments are never modified.
type Output ¶
type Output interface {
// Open returns a new reader positioned at the start of the output. A reader that
// implements io.Closer is closed after use. An error reports a failed capture.
Open() (io.Reader, error)
}
Output is captured phase output. Error hook matching reads it as a stream, so output of any size is never loaded into memory as a whole.
type Runner ¶
type Runner interface {
RunHook(ctx context.Context, kind HookKind, hook *schema.ComponentHook) (output Output, err error)
}
Runner executes one hook and reports its failure and captured output. The output feeds error hook matching and is never printed again. A nil output means nothing was captured.