Skip to content

feature

unit

Usage

Declare a flag, then read its value as feature.<name>.value:

terragrunt.hcl
feature "enable_monitoring" {
default = false
}
inputs = {
enable_monitoring = feature.enable_monitoring.value
}
Terminal window
# Plans with enable_monitoring = false.
terragrunt run -- plan
# Plans with enable_monitoring = true.
terragrunt run --feature enable_monitoring=true -- plan

Set a flag for a run with --feature, once per flag, or with the TG_FEATURE environment variable, as comma-separated pairs:

Terminal window
export TG_FEATURE=enable_monitoring=true,s3_version=v1.1.0
terragrunt run -- plan

When the flag’s default is a bool, Terragrunt converts the value to a bool, so enable_monitoring=true sets true. A value for any other flag is a string. In a run --all, the value applies to every unit that declares the flag.

Feature flags can also turn off a unit with an exclude block. See Feature flags for more uses.

Examples

Runs a hook only when the run_hook flag is true, and passes another flag to the module as an input.

terragrunt.hcl
feature "run_hook" {
default = false
}
feature "string_flag" {
default = "test"
}
terraform {
before_hook "feature_flag" {
commands = ["apply", "plan", "destroy"]
execute = feature.run_hook.value ? ["sh", "-c", "feature_flag_script.sh"] : ["sh", "-c", "exit", "0"]
}
}
inputs = {
string_feature_flag = feature.string_flag.value
}

Reads the default from an external feature flag service, e.g. LaunchDarkly or AWS AppConfig, through a command that prints the value.

terragrunt.hcl
feature "new_networking" {
default = run_cmd("--terragrunt-quiet", "./scripts/get-flag.sh", "new_networking")
}

Labels

name

Names the flag. The configuration reads its value as feature.<name>.value, and --feature <name>=<value> sets it.

Attributes

defaultany

The flag’s value when no --feature flag or TG_FEATURE environment variable sets it. It’s an expression, so it can call a function, e.g. run_cmd to ask an external feature flag service.

terragrunt.hcl
feature "s3_version" {
default = "v1.0.0"
}
terraform {
source = "git::git@github.com:acme/infrastructure-modules.git//storage/s3?ref=${feature.s3_version.value}"
}