The values block is optional. A config without it reads terragrunt.values.hcl unchecked, with or without the experiment.
A values block lists the values a unit or stack reads as values.<name>, each with an optional type, default, description, and nullable setting. Terragrunt reports a key the block doesn’t declare, a value of the wrong type, and a required value that nothing sets.
A config can have one values block, in the terragrunt.hcl of a unit or the terragrunt.stack.hcl of a stack. A values block in a file that another config includes, such as root.hcl, or in an autoinclude block, is an error.
How values resolve
Before Terragrunt evaluates the rest of the config, it resolves values from terragrunt.values.hcl:
A value the file doesn’t set, or sets to null, takes its default. A value without a default is required, and leaving it unset or null is an error.
With nullable = true, a value set to null stays null.
Each value converts to its type by the same rules as an OpenTofu variable, so "2" becomes the number 2 for a number value. The optional() attributes of an object type take their defaults.
A unit or stack with no terragrunt.values.hcl gets only its defaults. If it declares a required value, reading its config fails. That includes the catalog’s own copy: terragrunt hcl validate on a catalog unit fails, and so do stack generate and run --all from a directory that contains a catalog stack. Give every value a default to read the config without a values file.
When Terragrunt checks values
Terragrunt checks values only for a unit or stack whose config has a values block. terragrunt stack generate checks the values of each unit and stack block against that values block. stack run and run --all generate the stack first, so they run the check too. Terragrunt writes no terragrunt.values.hcl for a unit or stack that fails the check.
In this example, the stack passes the unit a key that the unit doesn’t declare:
live/terragrunt.stack.hcl
unit "app" {
source ="../catalog/units/app"
path ="app"
values ={
name="api"
tag= { team="payments" }
}
}
catalog/units/app/terragrunt.hcl
values {
value "name" {
type =string
}
value "instance_count" {
type =number
default =1
}
value "tags" {
type =map(string)
default ={}
}
}
Terminal window
terragruntstackgenerate--experimentvalues-block
Generation fails at the tag key and suggests the tags value the unit declares:
18:10:44.033 ERROR Error: Undeclared value "tag" for unit "app"
18:10:44.033 ERROR on /path/to/live/terragrunt.stack.hcl line 7, in unit "app":
18:10:44.033 ERROR 7: tag = { team = "payments" }
18:10:44.033 ERROR The unit at ../catalog/units/app does not declare a value named "tag".
18:10:44.033 ERROR Did you mean "tags"?
Terragrunt checks the values again when it reads the unit or stack config, so the same errors point at the line of a terragrunt.values.hcl file you edit by hand.
Checking references with hcl validate
terragrunt hcl validate checks values.<name> reads only in a config that has a values block, and skips HCL JSON files. It reports each read that the block doesn’t declare, including one inside try() or can(), which can never succeed.
Declares one value. Declaring the same name twice is an error.
namelabel
The name the unit or stack reads the value by, as values.<name>. It has to be a valid identifier.
typeoptional(type, any)
The type of the value, written as for an OpenTofu variable, e.g. map(string) or object({ size = optional(number, 1) }). Write the type without quotes, since "string" is an error.
defaultoptional(any)
The value to use when nothing sets it, or when it is set to null and nullable is false. Without a default, the value is required. A null default needs nullable = true. The default has to be a constant, so it can’t read local, values, or dependency, or call a function.
descriptionoptional(string)
Describes the value for readers of the config.
nullableoptional(bool, false)
When true, a null value stays null. Otherwise Terragrunt replaces null with the default, and reports an error for a value without one.