Skip to content
🎉 Terragrunt v1.0 is here! Read the announcement to learn more.

generate

Usage

Generate a stack of units based on configurations in a terragrunt.stack.hcl file.

Examples

Generate stacks of units using the configurations in all terragrunt.stack.hcl files found, starting in the current directory.

Terminal window
terragrunt stack generate

Generating a stack

terragrunt.stack.hcl
unit "mother" {
source = "units/chicken"
path = "mother"
}
unit "father" {
source = "./units/chicken"
path = "father"
}
unit "chick_1" {
source = "./units/chick"
path = "chicks/chick-1"
}
unit "chick_2" {
source = "units/chick"
path = "chicks/chick-2"
}

Running the following:

Terminal window
terragrunt stack generate

Generates the following stack:

  • terragrunt.stack.hcl
  • Directory.terragrunt-stack
    • Directorymother
      • terragrunt.hcl
    • Directoryfather
      • terragrunt.hcl
    • Directorychicks
      • Directorychick-1
        • terragrunt.hcl
      • Directorychick-2
        • terragrunt.hcl

Flags

--filter

Filter configurations using a flexible query language

Attribute-Based Filtering

Match stacks by their configuration attributes:

Terminal window
# Filter by name
terragrunt stack generate --filter 'prod | type=stack'
# Filter by type
terragrunt stack generate --filter 'type=stack'
# Filter by path
terragrunt stack generate --filter './envs/prod/** | type=stack'

Negation

Exclude paths using the ! prefix:

Terminal window
# Exclude by path
terragrunt stack generate --filter '!./prod/** | type=stack'

Union (Multiple Filters)

Specify multiple --filter flags to combine results using OR logic:

Terminal window
# Generate the dev and prod stacks
terragrunt stack generate --filter 'dev | type=stack' --filter 'prod | type=stack'
Type: list(string)

--no-cas

Disable the CAS (Content Addressable Storage) feature.

When this flag is set, Terragrunt skips all CAS operations and clones sources directly.

Generation or runs error when update_source_with_cas = true is set on any unit, stack, or terraform block reachable from the current invocation, since relative sources rewritten by CAS cannot be resolved without it.

Type: bool

Environment Variables:

  • TG_NO_CAS

--cas-clone-depth

When using CAS, pass this value to git clone --depth (default 1; -1 clones full history).

Controls the --depth value the CAS (Content Addressable Storage) uses when cloning a Git source. The default of 1 performs a shallow clone of the latest commit. Negative values clone the full history by omitting --depth entirely; zero is rejected because Git requires a positive depth.

When passing a negative value, use the --cas-clone-depth=-1 form so the leading dash isn’t parsed as a flag.

Type: integer
Default: 1

Environment Variables:

  • TG_CAS_CLONE_DEPTH