Skip to content
👷 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
terragrunt stack output

Get outputs from a stack of units in JSON format.

Terminal window
terragrunt stack output --format json

Get an output from a stack of units in raw format.

Terminal window
terragrunt stack output --format raw app.id

Executing terragrunt stack output in a stack directory produces an aggregated output from all units within the stack:

Terminal window
$ terragrunt stack output
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
$ 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:

Terminal window
$ terragrunt stack output project1_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.

FormatDescription
defaultFormat output as HCL.
jsonFormat output as JSON. This can be useful for integrations with other tools.
rawFormat output as a simple raw string. Useful for integration into bash scripts.

To retrieve outputs in structured JSON format:

Terminal window
$ 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"
]
}
}

json format

Accessing a specific list inside JSON format:

Terminal window
$ 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"
}
]
}

raw format

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:

Terminal window
$ terragrunt stack output --format raw project1_app2.data
app2

Flags

--format

Format stack output. (json, raw).

Specifies the output format for stack outputs. Available formats are:

  • default - Format output as HCL (default)
  • json - Format output as JSON for machine readability
  • raw - Format output as raw string for shell script integration

Example:

Terminal window
# JSON format
terragrunt stack output --format json
# Raw format
terragrunt stack output --format raw project1_app1.custom_value1
Type: string

Environment Variables:

  • TG_FORMAT

--json

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
terragrunt stack output --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=$(terragrunt stack output --raw app.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.

Type: bool

Environment Variables:

  • TG_NO_STACK_GENERATE