👷 The Terragrunt website redesign is Work In Progress! 👷For a list of outstanding TODOs see this.To give feedback, click here.
output
Usage
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.
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
Type: bool
Environment Variables:
TG_JSON
--raw
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)
Type: bool
Environment Variables:
TG_RAW
--no-stack-generate
Disable automatic stack regeneration before running the stack commands.
When enabled, Terragrunt will skip automatic stack regeneration before executing the command.
This is useful when you want to run operations using the existing .terragrunt-stack directory without regenerating it, improving execution speed and avoiding unnecessary changes.