Skip to content

stack

stack

Usage

The stack block defines a nested stack in a terragrunt.stack.hcl file. terragrunt stack generate fetches the stack’s terragrunt.stack.hcl file from source into path, writes values to a terragrunt.values.hcl file next to it, then generates the units and stacks that file defines:

terragrunt.stack.hcl
stack "dev" {
source = "../catalog/stacks/env"
path = "dev"
values = {
cidr = "10.0.0.0/16"
}
}
  • terragrunt.stack.hcl
  • Directory.terragrunt-stack
    • Directorydev
      • terragrunt.stack.hcl
      • terragrunt.values.hcl
      • Directory.terragrunt-stack
        • Directoryvpc
          • terragrunt.hcl
        • Directorydatabase
          • terragrunt.hcl

The generated terragrunt.stack.hcl file comes from source, reads values from terragrunt.values.hcl, and can pass them on to its own units:

.terragrunt-stack/dev/terragrunt.stack.hcl
unit "vpc" {
source = "git::https://github.com/acme/units.git//vpc?ref=v1.0.0"
path = "vpc"
values = {
cidr = values.cidr
}
}

Where the stack is generated

path is relative to the parent stack’s .terragrunt-stack directory. Set no_dot_terragrunt_stack to make it relative to the parent stack file’s directory instead:

By default:

terragrunt.stack.hcl
stack "prod" {
source = "../catalog/stacks/env"
path = "prod"
}
  • terragrunt.stack.hcl
  • Directory.terragrunt-stack
    • Directoryprod
      • terragrunt.stack.hcl

With no_dot_terragrunt_stack:

terragrunt.stack.hcl
stack "prod" {
source = "../catalog/stacks/env"
path = "prod"
no_dot_terragrunt_stack = true
}
  • terragrunt.stack.hcl
  • Directoryprod
    • terragrunt.stack.hcl

To generate more than one stack from a block, add an expansion block. To add units or stacks to the generated stack, add an autoinclude block.

To choose between a unit block and a stack block, see Unit and stack blocks.

Labels

name

Names the stack. Names are unique within a stack file. terragrunt stack output nests the stack’s outputs under its name, and stack.<name>.path refers to its generated directory in autoinclude blocks and in values.

Attributes

sourcestring

Where to fetch the stack’s terragrunt.stack.hcl file from, in the same syntax as the source attribute of the terraform block. The --source-map flag can replace it.

terragrunt.stack.hcl
stack "web" {
source = "git::https://github.com/acme/stacks.git//web?ref=v1.0.0"
path = "web"
}
pathstring

The directory to generate the stack in, relative to the parent stack’s .terragrunt-stack directory. Each stack in a stack file needs its own path. Terragrunt rejects an absolute path and a path that leaves the stack directory.

terragrunt.stack.hcl
stack "dev" {
source = "../catalog/stacks/environment"
path = "environments/dev"
}
valuesoptional(map(any))

Values to write to a terragrunt.values.hcl file next to the generated terragrunt.stack.hcl file. The nested stack file reads each one as values.<name>. A terragrunt.values.hcl file in the stack’s source supplies the values when the block sets none, and values replaces it otherwise.

terragrunt.stack.hcl
stack "dev" {
source = "../catalog/stacks/environment"
path = "dev"
values = {
environment = "development"
cidr = "10.0.0.0/16"
}
}
enabledoptional(bool, true)

When false, Terragrunt skips the stack during stack generation and leaves it out of terragrunt stack output. Changing it leaves the stack’s address and path unchanged. See enabled vs expansion.

terragrunt.stack.hcl
locals {
deploy_staging = false
}
stack "staging" {
source = "../catalog/stacks/environment"
path = "staging"
enabled = local.deploy_staging
}
no_dot_terragrunt_stackoptional(bool, false)

Resolves path against the parent stack file’s directory, so the stack is generated outside .terragrunt-stack. Use it to move existing units into a stack file without moving their directories or their state. See Where the stack is generated.

terragrunt.stack.hcl
stack "prod" {
source = "../catalog/stacks/environment"
path = "prod"
no_dot_terragrunt_stack = true
}
no_validationoptional(bool, false)

Skips the check that the generated directory has a terragrunt.stack.hcl file at its root. Terragrunt also skips it for a stack with no_dot_terragrunt_stack set. The --no-stack-validate flag skips it for every unit and stack.

terragrunt.stack.hcl
stack "legacy" {
source = "../catalog/stacks/legacy"
path = "legacy"
no_validation = true
}
update_source_with_casoptional(bool, false)

Lets a catalog’s stack file give source as a path relative to the catalog. Terragrunt rewrites it to a reference into its content-addressable store. See CAS integration.

stacks/platform/terragrunt.stack.hcl
stack "service" {
source = "../..//stacks/service"
path = "service"
update_source_with_cas = true
}
mutableoptional(bool, false)

Makes the files Terragrunt copies from its content-addressable store into the stack’s directory writable. Terragrunt writes them read-only by default, so an edit can’t reach the shared store.

terragrunt.stack.hcl
stack "service" {
source = "git::https://github.com/acme/stacks.git//app?ref=v1.0.0"
path = "service"
mutable = true
}