Skip to content

unit

stack

Usage

The unit block defines a unit in a terragrunt.stack.hcl file. terragrunt stack generate fetches the unit’s configuration from source into path, under the stack’s .terragrunt-stack directory, and writes values to a terragrunt.values.hcl file next to it:

terragrunt.stack.hcl
unit "vpc" {
source = "../catalog/units/vpc"
path = "vpc"
values = {
cidr = "10.0.0.0/16"
}
}
  • terragrunt.stack.hcl
  • Directory.terragrunt-stack
    • Directoryvpc
      • terragrunt.hcl
      • terragrunt.values.hcl

The generated terragrunt.hcl file comes from source, and reads values from terragrunt.values.hcl:

.terragrunt-stack/vpc/terragrunt.hcl
inputs = {
cidr = values.cidr
}

Where the unit is generated

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

By default:

terragrunt.stack.hcl
unit "rds" {
source = "../catalog/units/rds"
path = "rds"
}
  • terragrunt.stack.hcl
  • Directory.terragrunt-stack
    • Directoryrds
      • terragrunt.hcl

With no_dot_terragrunt_stack:

terragrunt.stack.hcl
unit "rds" {
source = "../catalog/units/rds"
path = "rds"
no_dot_terragrunt_stack = true
}
  • terragrunt.stack.hcl
  • Directoryrds
    • terragrunt.hcl

To generate more than one unit from a block, add an expansion block. To add dependencies or other configuration to the generated unit, add an autoinclude block.

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

Labels

name

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

Attributes

sourcestring

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

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

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

terragrunt.stack.hcl
unit "vpc" {
source = "../catalog/units/vpc"
path = "networking/vpc"
}
valuesoptional(map(any))

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

terragrunt.stack.hcl
unit "vpc" {
source = "../catalog/units/vpc"
path = "vpc"
values = {
vpc_name = "main"
cidr = "10.0.0.0/16"
}
}
enabledoptional(bool, true)

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

terragrunt.stack.hcl
locals {
deploy_canary = false
}
unit "canary" {
source = "../catalog/units/app"
path = "canary"
enabled = local.deploy_canary
}
no_dot_terragrunt_stackoptional(bool, false)

Resolves path against the stack file’s directory, so the unit 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 unit is generated.

terragrunt.stack.hcl
unit "rds" {
source = "../catalog/units/rds"
path = "rds"
no_dot_terragrunt_stack = true
}
no_validationoptional(bool, false)

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

terragrunt.stack.hcl
unit "legacy" {
source = "../catalog/units/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/service/terragrunt.stack.hcl
unit "service" {
source = "../..//units/service"
path = "service"
update_source_with_cas = true
}
mutableoptional(bool, false)

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

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