The `terragrunt stack output` command allows users to retrieve and interact with outputs from multiple units within a Terragrunt stack.
This feature simplifies handling infrastructure outputs by consolidating them into a single view.
Examples
Get outputs from a stack of units.
Terminal window
terragruntstackoutput
Get outputs from a stack of units in JSON format.
Terminal window
terragruntstackoutput--formatjson
Get an output from a stack of units in raw format.
Terminal window
terragruntstackoutput--formatrawapp.id
Executing terragrunt stack output in a stack directory produces an aggregated output from all units within the stack:
Terminal window
$terragruntstackoutput
service.output1="output1"
service.output2="output2"
db.output1="output1"
db.output2="output2"
Indexing outputs
To retrieve outputs for a specific unit, specify the unit name:
Terminal window
$terragruntstackoutputproject1_app1
project1_app1={
complex={
delta=0.02
id=2
name="name1"
timestamp="2025-02-07T21:05:51Z"
}
complex_list= [{
delta=0.02
id=10
name="name1"
timestamp="2025-02-07T21:05:51Z"
}, {
delta=0.03
id=20
name="name10"
timestamp="2025-02-07T21:05:51Z"
}]
custom_value1="value1"
data="app1"
list= ["1", "2","3"]
}
You can also retrieve a specific output from a unit:
Terminal window
$terragruntstackoutputproject1_app1.custom_value1
project1_app1.custom_value1="value1"
Output formats
Terragrunt provides multiple output formats for easier parsing and integration with other tools. The desired format can be specified using the --format CLI flag.
Format
Description
default
Format output as HCL.
json
Format output as JSON. This can be useful for integrations with other tools.
raw
Format output as a simple raw string. Useful for integration into bash scripts.
The raw format returns outputs as plain values without additional structure. When accessing lists or structured outputs, indexes are required to extract values.
The raw format returns outputs as plain values without additional structure. When accessing lists or structured outputs, indexes are required to extract values.
Format stack output as JSON. Alias for --format json.
A convenience flag that formats the stack output as JSON. This is equivalent to using --format json.
Example:
Terminal window
terragruntstackoutput--json
--rawoptional(bool)
Format stack output as raw string. Alias for --format raw.
A convenience flag that formats the stack output as a raw string. This is equivalent to using --format raw.
This is particularly useful when you need to use the output in shell scripts or other automation.
Example:
Terminal window
# Store the output in a variable
APP_ID=$(terragruntstackoutput--rawapp.id)
--discovery-boundaryoptional(string)
Directory that encloses graph discovery for filters, instead of the git repository root
Filter expressions that traverse the dependency graph reach beyond the working directory. Dependents (...{unit}) can live anywhere, so Terragrunt searches from the working directory up to the git repository root; dependencies ({unit}...) are declared by path and can point anywhere.
The --discovery-boundary flag is a single enclosure for that traversal: it replaces the git repository root as the outer limit, and a configuration that traversal reaches outside it is not returned, so find does not list it and run --all does not run it. Configurations inside the boundary are discovered as usual.
The boundary decides which configurations a command acts on, not which ones Terragrunt may read. A unit inside the boundary can declare a dependency outside it, and that dependency is still read and parsed: Terragrunt needs its configuration to fetch the outputs the dependent unit consumes, and it needs the dependency edge to order the units that do run. What the boundary withholds is the unit itself, which is left for a separate run to apply, the same way a dependency outside the working directory is treated today.
This matters in monorepos where environments are isolated from each other. When sibling environments cannot be parsed independently, the default search fails or wastes work reaching into them:
environments/
staging/
production/
test/
root.hcl
Bounding the traversal to the current environment keeps discovery inside it:
The boundary must be an existing directory. Relative paths are resolved against the working directory.
The boundary applies to what traversal reaches, so a command that names no filter keeps every configuration under the working directory even when the boundary sits below it. Narrow the working directory itself, with --working-dir, to change where discovery starts.
Where the boundary may sit depends on the directions the filters traverse. Dependent traversal searches from the working directory, so filters that traverse dependents require the boundary to be the working directory, one of its parents, or a directory inside it. A boundary inside the working directory starts the search there. Terragrunt rejects any other boundary, because it can never take effect. Dependency traversal follows declared paths outward from the units a filter matched and never consults the working directory, so filters that traverse only dependencies accept any directory, including one below the working directory. The inline (dir) operand follows the same rule.
Git-based expressions are the exception. For the units Terragrunt finds in the compared commits, a relative boundary resolves against the repository root, whether it comes from an inline (dir) operand or from --discovery-boundary. It can be any directory in the repository, and it must be a directory in at least one of the compared commits. A boundary at or above the repository root covers the whole commit. The flag only narrows which changed units Terragrunt finds when the filter traverses dependents. The working-directory walk still resolves the flag against the working directory, so run from the repository root to make both mean the same directory.