Documentation
¶
Overview ¶
Package terragrunt provides test helpers for running Terragrunt commands.
This package wraps the Terragrunt CLI to simplify integration testing of Terragrunt configurations. It supports both single-unit testing and multi-unit stack testing with dependency management.
For single-unit testing, you can use either this package or the terraform package with TerraformBinary set to "terragrunt". For stack testing with --all commands, use the dedicated functions in this package such as ApplyAllContextE and DestroyAllContextE.
Index ¶
- Constants
- Variables
- func ApplyAllContext(t testing.TestingT, ctx context.Context, options *Options) string
- func ApplyAllContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func ApplyContext(t testing.TestingT, ctx context.Context, options *Options) string
- func ApplyContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func BuildRunArgs(tgArgs []string, tfArgs []string) []string
- func BuildTerragruntArgs(opts *Options, commandArgs ...string) []string
- func CleanTerragruntJSON(input string) (string, error)
- func CleanTerragruntOutput(rawOutput string) string
- func DestroyAllContext(t testing.TestingT, ctx context.Context, options *Options) string
- func DestroyAllContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func DestroyContext(t testing.TestingT, ctx context.Context, options *Options) string
- func DestroyContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func ExtractJSONContent(rawOutput string) (string, error)
- func FilterLogLines(rawOutput string) string
- func FormatAllContext(t testing.TestingT, ctx context.Context, options *Options) string
- func FormatAllContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func GraphContext(t testing.TestingT, ctx context.Context, options *Options) string
- func GraphContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func HasWarning(opts *Options, commandOutput string) error
- func HclValidateContext(t testing.TestingT, ctx context.Context, options *Options) string
- func HclValidateContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func InitAndApplyContext(t testing.TestingT, ctx context.Context, options *Options) string
- func InitAndApplyContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func InitAndPlanContext(t testing.TestingT, ctx context.Context, options *Options) string
- func InitAndPlanContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func InitAndValidateContext(t testing.TestingT, ctx context.Context, options *Options) string
- func InitAndValidateContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func InitContext(t testing.TestingT, ctx context.Context, options *Options) string
- func InitContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func IsLogLine(line string) bool
- func IsMetadataLine(line string) bool
- func OutputAllJSONContext(t testing.TestingT, ctx context.Context, options *Options) string
- func OutputAllJSONContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func OutputJSONContext(t testing.TestingT, ctx context.Context, options *Options, key string) string
- func OutputJSONContextE(t testing.TestingT, ctx context.Context, options *Options, key string) (string, error)
- func PlanAllExitCodeContext(t testing.TestingT, ctx context.Context, options *Options) int
- func PlanAllExitCodeContextE(t testing.TestingT, ctx context.Context, options *Options) (int, error)
- func PlanContext(t testing.TestingT, ctx context.Context, options *Options) string
- func PlanContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func PlanExitCodeContext(t testing.TestingT, ctx context.Context, options *Options) int
- func PlanExitCodeContextE(t testing.TestingT, ctx context.Context, options *Options) (int, error)
- func PrepareOptions(opts *Options) error
- func RemoveLogLines(rawOutput string) string
- func RenderContext(t testing.TestingT, ctx context.Context, options *Options) string
- func RenderContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func RenderJSONContext(t testing.TestingT, ctx context.Context, options *Options) string
- func RenderJSONContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func RunContext(t testing.TestingT, ctx context.Context, options *Options, tgArgs []string, ...) string
- func RunContextE(t testing.TestingT, ctx context.Context, options *Options, tgArgs []string, ...) (string, error)
- func StackCleanContext(t testing.TestingT, ctx context.Context, options *Options) string
- func StackCleanContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func StackGenerateContext(t testing.TestingT, ctx context.Context, options *Options) string
- func StackGenerateContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func StackOutputAllContext(t testing.TestingT, ctx context.Context, options *Options) map[string]any
- func StackOutputAllContextE(t testing.TestingT, ctx context.Context, options *Options) (map[string]any, error)
- func StackOutputContext(t testing.TestingT, ctx context.Context, options *Options, key string) string
- func StackOutputContextE(t testing.TestingT, ctx context.Context, options *Options, key string) (string, error)
- func StackOutputJSONContext(t testing.TestingT, ctx context.Context, options *Options, key string) string
- func StackOutputJSONContextE(t testing.TestingT, ctx context.Context, options *Options, key string) (string, error)
- func StackOutputListAllContext(t testing.TestingT, ctx context.Context, options *Options) []string
- func StackOutputListAllContextE(t testing.TestingT, ctx context.Context, options *Options) ([]string, error)
- func StackRunContext(t testing.TestingT, ctx context.Context, options *Options) string
- func StackRunContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func ValidateAllContext(t testing.TestingT, ctx context.Context, options *Options) string
- func ValidateAllContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func ValidateContext(t testing.TestingT, ctx context.Context, options *Options) string
- func ValidateContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
- func ValidateOptions(opts *Options) error
- type Options
Constants ¶
const ( DefaultTerragruntBinary = "terragrunt" NonInteractiveFlag = "--non-interactive" TerragruntLogFormatKey = "TG_LOG_FORMAT" TerragruntLogCustomKey = "TG_LOG_CUSTOM_FORMAT" TerragruntNoTipsKey = "TG_NO_TIPS" DefaultLogFormat = "key-value" DefaultLogCustomFormat = "%msg(color=disable)" )
Key concepts: - Options: Configure HOW the test framework executes tg (directories, retry logic, logging) - TerragruntArgs: Global terragrunt flags (e.g., --log-level, --no-color) - TerraformArgs: Command-specific OpenTofu/Terraform args (e.g., -upgrade for init, or the command itself for stack run) - Use Options.TerragruntDir to specify WHERE to run tg
Example:
ctx := t.Context()
// For init with OpenTofu/Terraform flags
InitContextE(t, ctx, &Options{
TerragruntDir: "/path/to/config",
TerragruntArgs: []string{"--log-level", "info"},
TerraformArgs: []string{"-upgrade=true"},
})
// For run-all with global flags
ApplyAllContextE(t, ctx, &Options{
TerragruntDir: "/path/to/config",
TerragruntArgs: []string{"--no-color"},
})
Constants for test framework configuration and environment variables
Variables ¶
var ErrEmptyTfArgs = errors.New("tfArgs cannot be empty; at minimum, an OpenTofu/Terraform command (e.g. \"apply\") is required")
ErrEmptyTfArgs is returned when tfArgs is empty in a call that requires at least one OpenTofu/Terraform command argument (e.g. "apply", "plan").
var ErrMissingTerragruntDir = errors.New("TerragruntDir is required")
ErrMissingTerragruntDir is returned when the required TerragruntDir field is empty in the provided Options.
var ErrNilOptions = errors.New("options cannot be nil")
ErrNilOptions is returned when a nil Options pointer is passed to a function that requires a valid configuration.
Functions ¶
func ApplyAllContext ¶
ApplyAllContext runs terragrunt run --all apply with the given options and returns stdout/stderr. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. Note that this method does NOT call destroy and assumes the caller is responsible for cleaning up any resources created by running apply.
func ApplyAllContextE ¶
ApplyAllContextE runs terragrunt run --all apply with the given options and returns stdout/stderr. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. Note that this method does NOT call destroy and assumes the caller is responsible for cleaning up any resources created by running apply.
func ApplyContext ¶
ApplyContext runs terragrunt run apply for a single unit and returns stdout/stderr. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func ApplyContextE ¶
ApplyContextE runs terragrunt run -- apply for a single unit and returns stdout/stderr. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func BuildRunArgs ¶
BuildRunArgs constructs the argument list for a terragrunt run command. The -- separator disambiguates Terragrunt flags from OpenTofu/Terraform flags:
run [tgArgs...] -- [tfArgs...]
func BuildTerragruntArgs ¶
BuildTerragruntArgs constructs the final argument list for a terragrunt command. Arguments are ordered as: TerragruntArgs → --non-interactive → commandArgs → TerraformArgs.
func CleanTerragruntJSON ¶
CleanTerragruntJSON cleans the JSON output from a terragrunt stack command that returns a single combined JSON object. Returns an error if the output contains multiple JSON objects (use ExtractJSONContent directly for multi-object output).
Example input (raw tg JSON output):
time=2023-07-11T10:30:45Z level=info prefix=mother tf-path=terraform msg=Initializing...
time=2023-07-11T10:30:46Z level=info prefix=mother tf-path=terraform msg=Running command...
{"mother":{"output":"./test.txt"},"father":{"output":"./test.txt"}}
Example output (cleaned and formatted):
{
"mother": {
"output": "./test.txt"
},
"father": {
"output": "./test.txt"
}
}
func CleanTerragruntOutput ¶
CleanTerragruntOutput extracts the actual output value from terragrunt stack's verbose output.
Example input (raw tg output):
time=2023-07-11T10:30:45Z level=info prefix=foo tf-path=terraform msg=Initializing... time=2023-07-11T10:30:46Z level=info prefix=foo tf-path=terraform msg=Running command... "my-bucket-name"
Example output (cleaned):
my-bucket-name
For JSON values, it preserves the structure: Input:
time=2023-07-11T10:30:45Z level=info prefix=foo tf-path=terraform msg=Running...
{"vpc_id": "vpc-12345", "subnet_ids": ["subnet-1", "subnet-2"]}
Output:
{"vpc_id": "vpc-12345", "subnet_ids": ["subnet-1", "subnet-2"]}
func DestroyAllContext ¶
DestroyAllContext runs terragrunt run --all destroy with the given options and returns stdout. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func DestroyAllContextE ¶
DestroyAllContextE runs terragrunt run --all -- destroy with the given options and returns stdout. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func DestroyContext ¶
DestroyContext runs terragrunt run destroy for a single unit and returns stdout/stderr. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func DestroyContextE ¶
DestroyContextE runs terragrunt run -- destroy for a single unit and returns stdout/stderr. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func ExtractJSONContent ¶
ExtractJSONContent extracts only JSON objects from terragrunt output, filtering out log lines and other non-JSON content like "Group 1" or "- Unit ./foo". Uses json.Decoder to correctly handle braces inside JSON string values.
func FilterLogLines ¶
FilterLogLines removes terragrunt log lines while preserving original indentation. Unlike RemoveLogLines (which trims whitespace for JSON extraction), this keeps leading whitespace intact so HCL output structure is preserved.
func FormatAllContext ¶
FormatAllContext runs terragrunt hcl format to format all terragrunt.hcl files and returns stdout/stderr. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func FormatAllContextE ¶
FormatAllContextE runs terragrunt hcl format to format all terragrunt.hcl files and returns stdout/stderr. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func GraphContext ¶
GraphContext runs terragrunt dag graph and returns the DOT-format dependency graph. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. This is useful for verifying dependency relationships between terragrunt units. Log lines are stripped from the output so the result is clean DOT format.
func GraphContextE ¶
GraphContextE runs terragrunt dag graph and returns the DOT-format dependency graph. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. This is useful for verifying dependency relationships between terragrunt units. Log lines are stripped from the output so the result is clean DOT format.
func HasWarning ¶
HasWarning checks if the command output contains any warnings that should be treated as errors. It uses regex patterns defined in opts.WarningsAsErrors to match warning messages.
func HclValidateContext ¶
HclValidateContext runs terragrunt hcl validate to check terragrunt.hcl syntax. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. This validates Terragrunt HCL configuration and can check for mis-aligned inputs. Use TerraformArgs to pass additional flags like "--inputs" or "--strict".
Examples:
HclValidateContext(t, ctx, options) // Basic syntax check
HclValidateContext(t, ctx, &Options{TerraformArgs: []string{"--inputs"}}) // Check input alignment
func HclValidateContextE ¶
HclValidateContextE runs terragrunt hcl validate to check terragrunt.hcl syntax. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. This validates Terragrunt HCL configuration and can check for mis-aligned inputs. Use TerraformArgs to pass additional flags like "--inputs" or "--strict".
func InitAndApplyContext ¶
InitAndApplyContext runs terragrunt init followed by apply for a single unit and returns the apply stdout/stderr. The provided context is passed through to both the init and apply command executions.
func InitAndApplyContextE ¶
func InitAndApplyContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
InitAndApplyContextE runs terragrunt init followed by apply for a single unit and returns the apply stdout/stderr. The provided context is passed through to both the init and apply command executions.
func InitAndPlanContext ¶
InitAndPlanContext runs terragrunt init followed by plan for a single unit and returns the plan stdout/stderr. The provided context is passed through to both the init and plan command executions.
func InitAndPlanContextE ¶
InitAndPlanContextE runs terragrunt init followed by plan for a single unit and returns the plan stdout/stderr. The provided context is passed through to both the init and plan command executions.
func InitAndValidateContext ¶
InitAndValidateContext runs terragrunt init followed by validate for a single unit and returns the validate stdout/stderr. The provided context is passed through to both the init and validate command executions.
func InitAndValidateContextE ¶
func InitAndValidateContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
InitAndValidateContextE runs terragrunt init followed by validate for a single unit and returns the validate stdout/stderr. The provided context is passed through to both the init and validate command executions.
func InitContext ¶
InitContext calls terragrunt run init and returns stdout/stderr. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func InitContextE ¶
InitContextE calls terragrunt run -- init and returns stdout/stderr. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func IsMetadataLine ¶
IsMetadataLine checks if a line is terragrunt metadata (e.g., "Group 1", "- Unit ./foo").
func OutputAllJSONContext ¶
OutputAllJSONContext runs terragrunt run --all output -json and returns the raw JSON string. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. Note: Current terragrunt versions return separate JSON objects per module, not a combined object.
func OutputAllJSONContextE ¶
func OutputAllJSONContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
OutputAllJSONContextE runs terragrunt run --all output -json and returns the raw JSON string. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. Note: Current terragrunt versions return separate JSON objects per module, not a combined object.
func OutputJSONContext ¶
func OutputJSONContext(t testing.TestingT, ctx context.Context, options *Options, key string) string
OutputJSONContext runs terragrunt run output -json for a single unit and returns clean JSON. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. If key is non-empty, returns the JSON value for that specific output. If key is empty, returns all outputs as JSON.
func OutputJSONContextE ¶
func OutputJSONContextE(t testing.TestingT, ctx context.Context, options *Options, key string) (string, error)
OutputJSONContextE runs terragrunt run output -json for a single unit and returns clean JSON. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. If key is non-empty, returns the JSON value for that specific output. If key is empty, returns all outputs as JSON.
func PlanAllExitCodeContext ¶
PlanAllExitCodeContext runs terragrunt run --all plan with the given options and returns the detailed exit code. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. This will fail the test if there is an error in the command.
func PlanAllExitCodeContextE ¶
func PlanAllExitCodeContextE(t testing.TestingT, ctx context.Context, options *Options) (int, error)
PlanAllExitCodeContextE runs terragrunt run --all -- plan with the given options and returns the detailed exit code. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func PlanContext ¶
PlanContext runs terragrunt run plan for a single unit and returns stdout/stderr. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func PlanContextE ¶
PlanContextE runs terragrunt run -- plan for a single unit and returns stdout/stderr. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. Uses -lock=false since plan is a read-only operation that does not need state locking.
func PlanExitCodeContext ¶
PlanExitCodeContext runs terragrunt run plan for a single unit and returns the detailed exit code. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. This will fail the test if there is an error in the command.
func PlanExitCodeContextE ¶
PlanExitCodeContextE runs terragrunt run -- plan for a single unit and returns the detailed exit code. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func PrepareOptions ¶
PrepareOptions validates options and sets defaults.
func RemoveLogLines ¶
RemoveLogLines removes terragrunt log lines and metadata from output.
func RenderContext ¶
RenderContext runs terragrunt render to output the resolved terragrunt configuration as HCL. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. This is useful for verifying merged includes, resolved dependencies, and executed functions without actually applying any changes.
func RenderContextE ¶
RenderContextE runs terragrunt render to output the resolved terragrunt configuration as HCL. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. This is useful for verifying merged includes, resolved dependencies, and executed functions without actually applying any changes. Log lines are stripped from the output.
func RenderJSONContext ¶
RenderJSONContext runs terragrunt render --format json and returns the cleaned JSON output. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. This is useful for programmatic assertions on the resolved terragrunt configuration.
func RenderJSONContextE ¶
RenderJSONContextE runs terragrunt render --format json and returns the cleaned JSON output. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. This is useful for programmatic assertions on the resolved terragrunt configuration.
func RunContext ¶
func RunContext(t testing.TestingT, ctx context.Context, options *Options, tgArgs []string, tfArgs []string) string
RunContext runs terragrunt run [tgArgs...] -- [tfArgs...] with the given options and returns stdout/stderr. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. This is a generic wrapper that allows running any OpenTofu/Terraform command through terragrunt run. The -- separator disambiguates Terragrunt flags from OpenTofu/Terraform flags. The OpenTofu/Terraform command (e.g. "apply") should be the first element of tfArgs.
func RunContextE ¶
func RunContextE(t testing.TestingT, ctx context.Context, options *Options, tgArgs []string, tfArgs []string) (string, error)
RunContextE runs terragrunt run [tgArgs...] -- [tfArgs...] with the given options and returns stdout/stderr. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. This is a generic wrapper that allows running any OpenTofu/Terraform command through terragrunt run. The -- separator disambiguates Terragrunt flags from OpenTofu/Terraform flags. The OpenTofu/Terraform command (e.g. "apply") should be the first element of tfArgs.
func StackCleanContext ¶
StackCleanContext calls terragrunt stack clean to remove the .terragrunt-stack directory. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. This command cleans up the generated stack files created by stack generate or stack run.
func StackCleanContextE ¶
StackCleanContextE calls terragrunt stack clean to remove the .terragrunt-stack directory. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. This command cleans up the generated stack files created by stack generate or stack run.
func StackGenerateContext ¶
StackGenerateContext calls terragrunt stack generate and returns stdout/stderr. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func StackGenerateContextE ¶
func StackGenerateContextE(t testing.TestingT, ctx context.Context, options *Options) (string, error)
StackGenerateContextE calls terragrunt stack generate and returns stdout/stderr. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func StackOutputAllContext ¶
func StackOutputAllContext(t testing.TestingT, ctx context.Context, options *Options) map[string]any
StackOutputAllContext gets all stack outputs and returns them as a map[string]any. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func StackOutputAllContextE ¶
func StackOutputAllContextE(t testing.TestingT, ctx context.Context, options *Options) (map[string]any, error)
StackOutputAllContextE gets all stack outputs and returns them as a map[string]any. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func StackOutputContext ¶
func StackOutputContext(t testing.TestingT, ctx context.Context, options *Options, key string) string
StackOutputContext calls terragrunt stack output for the given variable and returns its value as a string. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func StackOutputContextE ¶
func StackOutputContextE(t testing.TestingT, ctx context.Context, options *Options, key string) (string, error)
StackOutputContextE calls terragrunt stack output for the given variable and returns its value as a string. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func StackOutputJSONContext ¶
func StackOutputJSONContext(t testing.TestingT, ctx context.Context, options *Options, key string) string
StackOutputJSONContext calls terragrunt stack output for the given variable and returns the result as a JSON string. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. If key is an empty string, it will return all the output variables.
func StackOutputJSONContextE ¶
func StackOutputJSONContextE(t testing.TestingT, ctx context.Context, options *Options, key string) (string, error)
StackOutputJSONContextE calls terragrunt stack output for the given variable and returns the result as a JSON string. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control. If key is an empty string, it will return all the output variables.
func StackOutputListAllContext ¶
StackOutputListAllContext gets all stack output variable names and returns them as a slice. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func StackOutputListAllContextE ¶
func StackOutputListAllContextE(t testing.TestingT, ctx context.Context, options *Options) ([]string, error)
StackOutputListAllContextE gets all stack output variable names and returns them as a slice. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func StackRunContext ¶
StackRunContext calls terragrunt stack run and returns stdout/stderr. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func StackRunContextE ¶
StackRunContextE calls terragrunt stack run and returns stdout/stderr. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func ValidateAllContext ¶
ValidateAllContext runs terragrunt run --all validate with the given options and returns stdout/stderr. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func ValidateAllContextE ¶
ValidateAllContextE runs terragrunt run --all -- validate with the given options and returns stdout/stderr. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func ValidateContext ¶
ValidateContext runs terragrunt run validate for a single unit and returns stdout/stderr. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func ValidateContextE ¶
ValidateContextE runs terragrunt run -- validate for a single unit and returns stdout/stderr. The provided context is passed through to the underlying command execution, allowing for timeout and cancellation control.
func ValidateOptions ¶
ValidateOptions validates that required options are provided.
Types ¶
type Options ¶
type Options struct {
// Optional stdin to pass to OpenTofu/Terraform commands
Stdin io.Reader
// Test framework retry and error handling (NOT passed to tg command line)
RetryableTerraformErrors map[string]string // Retryable error patterns
EnvVars map[string]string // Environment variables for command execution
WarningsAsErrors map[string]string // Warnings to treat as errors
// Test framework configuration (NOT passed to tg command line)
Logger *logger.Logger // Logger for command output
// Complex configuration that requires special formatting (NOT raw command-line args)
BackendConfig map[string]any // Backend configuration (formatted specially)
// Test framework configuration (NOT passed to tg command line)
TerragruntBinary string // The tg binary to use (should be "terragrunt")
PluginDir string // Plugin directory (formatted specially)
TerragruntDir string // The directory containing the tg configuration
// Global terragrunt command-line flags (placed BEFORE the command)
// Example: []string{"--log-level", "info", "--no-color"}
TerragruntArgs []string
// Command-specific OpenTofu/Terraform flags (placed AFTER the command)
// Example: []string{"-upgrade=true"} for init, or []string{"plan"} for stack run
TerraformArgs []string
MaxRetries int // Maximum number of retries
TimeBetweenRetries time.Duration // Time between retries
}
Options represent the configuration options for tg test execution.
This struct is divided into two clear categories:
1. TEST FRAMEWORK CONFIGURATION:
- Controls HOW the test framework executes tg
- Includes: binary paths, directories, retry logic, logging, environment
- These are NOT passed as command-line arguments to tg
2. TG COMMAND ARGUMENTS:
- TerragruntArgs: Global terragrunt flags (placed BEFORE the command)
- TerraformArgs: Command-specific flags (placed AFTER the command)
- These ARE passed directly to tg in the appropriate positions
This separation eliminates confusion about which settings control the test framework vs which become tg command-line arguments.