Generate a simplified version of the Terragrunt configuration with all includes and dependencies resolved.
Examples
Render the configurations for the current unit in JSON format.
Terminal window
terragruntrender--format=json
Render the Terragrunt configuration in the current working directory, with as much work done as possible beforehand (that is, with all includes merged, dependencies resolved/interpolated, function calls executed, etc).
Example:
The following terragrunt.hcl:
locals {
aws_region ="us-east-1"
}
inputs ={
aws_region= local.aws_region
}
Renders to the following HCL by default:
Terminal window
$terragruntrender
locals{
aws_region="us-east-1"
}
inputs={
aws_region="us-east-1"
}
Note the resolution of the aws_region local, making it easier to read the final evaluated configuration at a glance.
Renders to the following JSON when the --format json flag is used:
Terminal window
$terragruntrender--formatjson
{
"locals":{"aws_region":"us-east-1"},
"inputs":{"aws_region":"us-east-1"}
//NOTE:otherattributesareomittedforbrevity
}
You can also use the --write flag to write the rendered configuration to a canonically named file in the same working directory as the terragrunt.hcl file.
Example:
Terminal window
# Note the use of the `--json` shortcut flag.
terragruntrender--json--write
This will write the rendered configuration to terragrunt.rendered.json in the current working directory.
This can be useful when rendering many configurations in a given directory, and you want to keep the rendered configurations in the same directory as the original configurations, without leveraging external tools or scripts.
This is also useful when combined with the --all flag, which will render all configurations discovered from the current working directory.
Terminal window
# Note the use of the `-w` alias for the `--write` flag.
terragruntrender--all--json-w
This will render all configurations discovered from the current working directory and write the rendered configurations to terragrunt.rendered.json files adjacent to the configurations they are derived from.
Expanded dependencies
A dependency block that carries an expansion block renders as it was written, references and all, followed by the elements it expanded into. Each element is commented out, with its body resolved against the iteration it came from:
Terminal window
$terragruntrender
dependency"aurora"{
expansion{
for_each=toset(["web", "api"])
}
config_path="../aurora-${each.key}"
}
# Expands to:
#
# dependency "aurora" {
# config_path = "../aurora-api"
# }
#
# dependency "aurora" {
# config_path = "../aurora-web"
# }
count reads the same way:
Terminal window
$terragruntrender
dependency"shard"{
expansion{
count=2
}
config_path="../shard-${count.index}"
}
# Expands to:
#
# dependency "shard" {
# config_path = "../shard-0"
# }
#
# dependency "shard" {
# config_path = "../shard-1"
# }
The expanded blocks are in comments because they are not a valid Terragrunt configuration: they all carry one label, and only the last block with a given label can be referenced. Terragrunt warns about that, and rejects it outright under the duplicate-dependency-labelsstrict control. They are present as comments to help you predict how Terragrunt will expand the block with an expansion block.
A dependency block with no expansion block renders as it always has.
A configuration written in JSON reads the same way. It has no HCL to quote, so render writes the block as the HCL that means the same thing and previews the elements underneath it:
Terminal window
$catterragrunt.hcl.json
{"dependency":{"shard":{
"expansion":{"count":2},
"config_path":"../shard-${count.index}"
}}}
$terragruntrender
dependency"shard"{
expansion{
count=2
}
config_path="../shard-${count.index}"
}
# Expands to:
#
# dependency "shard" {
# config_path = "../shard-0"
# }
#
# dependency "shard" {
# config_path = "../shard-1"
# }
--format json has no comment to preview the elements in, and its dependency map is keyed by label, which every element shares. It emits the block as it was written, references and all:
Terminal window
$terragruntrender--formatjson
{
"dependency":{
"shard":{
"expansion":{"count":2},
"config_path":"../shard-${count.index}",
"skip_outputs":true
}
}
}
An expanded block uses the names the configuration writes, such as skip_outputs, rather than the resolved names an unexpanded block gets, such as skip. Nothing about it has been resolved, so it appears as declared.
Whichever syntax you write and whichever format you ask for, rendering the output again returns it unchanged.
Flags
--formatoptional(string)
Use the specified format for the rendered configuration. Supported values (hcl, json). default hcl.
Controls the output format of the rendered Terragrunt configuration. Supports:
hcl - Output in HCL format (default)
json - Output in JSON format
The HCL format is human-readable and matches the original configuration style, while JSON format is useful for programmatic processing.
Example:
Terminal window
# Render as HCL (default)
terragruntrender
# Render as JSON
terragruntrender--formatjson
Environment Variables:
TG_FORMAT
--writeoptional(bool)
Write the rendered configuration to a file (terragrunt.rendered.hcl or terragrunt.rendered.json by default).
Example:
Terminal window
terragruntrender--write--json
This will write the rendered configuration to terragrunt.rendered.json in the current working directory.
Aliases:
w
Environment Variables:
TG_WRITE
--alloptional(bool)
Render all configurations discovered from the current working directory.
Example:
Terminal window
terragruntrender--all--json
This renders all configurations discovered from the current working directory and prints them to stdout.
Combining this with the --write flag will write the rendered configurations to terragrunt.rendered.json files adjacent to the configurations they are derived from.
Terminal window
terragruntrender-a--json--write
Aliases:
a
Environment Variables:
TG_ALL
--filteroptional(list(string))
Render only the units that match a filter query
Render only the units that match the filter query. Passing --filter turns on --all.
Terminal window
terragruntrender--filter'./prod/**'
Environment Variables:
TG_FILTER
--filter-affectedoptional(bool)
Render only the units affected by changes between the default branch and HEAD
Render only the units modified, added, or removed between the default branch and HEAD. Equivalent to --filter '[main...HEAD]', with your repository’s default branch in place of main. Combine it with --all.
Directory that encloses graph discovery for filters, instead of the git repository root
Replace the git repository root as the outer limit for filter expressions that traverse the dependency graph. render does not render a unit that traversal reaches outside the boundary.