--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'Graph-Based Filtering
Filter configurations based on dependency relationships using graph traversal. Use ellipsis (...) to traverse the dependency graph and caret (^) to exclude the target from results.
Syntax variants:
foo...- Include target and all dependencies (things it depends on)...foo- Include target and all dependents (things that depend on it)...foo...- Include target, dependencies, and dependents^foo...- Include only dependencies (exclude target)...^foo- Include only dependents (exclude target)...^foo...- Include dependencies and dependents (exclude target)
# Find 'service' and everything it depends onterragrunt find --filter 'service...'
# Find 'vpc' and everything that depends on itterragrunt find --filter '...vpc'
# Find complete dependency graph for 'db'terragrunt find --filter '...db...'
# Find dependencies of 'service' but exclude 'service' itselfterragrunt find --filter '^service...'
# Combine graph traversal with path filters (note the use of braces to escape the path)terragrunt find --filter '{./apps/service}...'
# Combine graph traversal with attribute filtersterragrunt find --filter '...type=unit'
# Refine graph results with intersectionterragrunt find --filter 'service... | external=false'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.