--filter
Filter configurations using a flexible query language
The --filter flag provides a sophisticated querying syntax for targeting specific units and stacks in Terragrunt commands.
Usage
terragrunt find --filter 'app*'terragrunt list --filter './prod/** | type=unit'terragrunt run --all --filter './prod/**' -- planterragrunt hcl fmt --filter './prod/**'terragrunt hcl validate --filter 'type=unit'Name-Based Filtering
Match configurations by their name using exact matches or glob patterns:
# Exact matchterragrunt find --filter app1
# Glob patternterragrunt find --filter 'app*'Path-Based Filtering
Match configurations by their file system path:
# Relative paths with globsterragrunt find --filter './envs/prod/**'
# Absolute pathsterragrunt find --filter '/absolute/path/to/envs/dev/apps/*'Attribute-Based Filtering
Match configurations by their configuration attributes:
# Filter by typeterragrunt find --filter 'type=unit'terragrunt find --filter 'type=stack'
# Filter by external dependency statusterragrunt find --filter 'external=false'
# Filter by files readterragrunt find --filter 'reading=shared.hcl'terragrunt find --filter 'reading=common/*.hcl' # Globs supported!terragrunt find --filter 'reading=config/**' # Double-wildcard globs are required filtering on files nested in subdirectories.terragrunt find --filter 'reading=config/vars.tfvars'Negation
Exclude configurations using the ! prefix:
# Exclude by nameterragrunt find --filter '!app1'
# Exclude by pathterragrunt find --filter '!./prod/**'Intersection (Refinement)
Use the | operator to refine results:
# Find all units in prod directoryterragrunt find --filter './prod/** | type=unit'
# Chain multiple filtersterragrunt find --filter './dev/** | type=unit | !name=unit1'Union (Multiple Filters)
Specify multiple --filter flags to combine results using OR logic:
# Find components named 'unit1' OR 'stack1'terragrunt find --filter unit1 --filter stack1Supported Commands
Currently supported in:
Planned for future releases:
Learn More
For comprehensive examples and advanced usage patterns, see the Filters feature documentation.