docs/src/data/commands/stack/output.mdx
Executing terragrunt stack output in a stack directory produces an aggregated output from all units within the stack:
$ terragrunt stack output
service.output1 = "output1"
service.output2 = "output2"
db.output1 = "output1"
db.output2 = "output2"
To retrieve outputs for a specific unit, specify the unit name:
$ terragrunt stack output project1_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:
$ terragrunt stack output project1_app1.custom_value1
project1_app1.custom_value1 = "value1"
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. |
To retrieve outputs in structured JSON format:
$ terragrunt stack output --format json project1_app2
{
"project1_app2": {
"complex": {
"delta": 0.02,
"id": 2,
"name": "name2",
"timestamp": "2025-02-07T21:05:51Z"
},
"complex_list": [
{
"delta": 0.02,
"id": 2,
"name": "name2",
"timestamp": "2025-02-07T21:05:51Z"
},
{
"delta": 0.03,
"id": 2,
"name": "name3",
"timestamp": "2025-02-07T21:05:51Z"
}
],
"custom_value2": "value2",
"data": "app2",
"list": [
"a",
"b",
"c"
]
}
}
Accessing a specific list inside JSON format:
$ terragrunt stack output --format json project1_app2.complex_list
{
"project1_app2.complex_list": [
{
"delta": 0.02,
"id": 2,
"name": "name2",
"timestamp": "2025-02-07T21:05:51Z"
},
{
"delta": 0.03,
"id": 2,
"name": "name3",
"timestamp": "2025-02-07T21:05:51Z"
}
]
}
The raw format returns outputs as plain values without additional structure. When accessing lists or structured outputs, indexes are required to extract values.
Retrieving a simple value:
$ terragrunt stack output --format raw project1_app2.data
app2