Terraform
output block reference for component configurations
Use the output block in a Stack to expose information about your Stack's infrastructure in the HCP Terraform UI.
Background
Define output blocks in the <NAME>.tfcomponent.hcl file, to expose information about your Stack's infrastructure in the HCP Terraform UI.
If you want to expose a value from a Stack to use another Stack, refer to Pass data from one Stack to another instead. If you are declaring a output block in a traditional Terraform configuration file, ending in .tf, refer to the Terraform configuration output block reference instead.
Configuration model
The output block supports the following arguments:
output "<LABEL>"blocktypetype constraintvalueexpressiondescriptionstringsensitivebooleanephemeralboolean
Complete configuration
All available arguments are defined in the following output block:
output "<LABEL>" {
description = "<STRING>"
type = <TYPE>
value = <EXPRESSION>
sensitive = <true|false>
ephemeral = <true|false>
}
Specification
In a component configuration file, the output block supports the following configuration.
output "<LABEL>"
The label after the output keyword is a name for the output, which must be unique among all outputs in the same component configuration. The name of an output can be any valid identifier.
The following arguments are supported in an output block:
| Argument | Description | Type | Required? |
|---|---|---|---|
type | The type constraint for this output value. | Type constraint | Required |
value | The value Terraform returns for this output. | Expression | Required |
description | A description of the output's purpose and how to use it. | String | Optional |
sensitive | Specifies if Terraform hides this value in the UI and logs. | Boolean | Optional |
ephemeral | Specifies that Terraform must exclude this value from plans and state. | Boolean | Optional |
type
The type argument specifies the type constraint for the output value. Component configurations require you to explicitly define the type of each output.
output "<LABEL>" {
type = <TYPE_CONSTRAINT>
#...
}
For details about types, constructors, and conversions, refer to Type constraints.
Summary
- Data type: Type constraint
- Default: None
- Required: Yes
value
The value argument specifies the expression that Terraform evaluates and exposes to the HCP Terraform UI.
output "<LABEL>" {
type = <TYPE_CONSTRAINT>
value = <EXPRESSION>
}
In component configurations, outputs commonly reference component outputs and other Stack resources, such as component.<COMPONENT_NAME>.<OUTPUT_NAME>.
Summary
- Data type: Expression
- Default: None
- Required: Yes
description
The description argument documents the purpose of the output and how consumers should use it.
output "<LABEL>" {
description = "<DESCRIPTION>"
type = <TYPE_CONSTRAINT>
value = <EXPRESSION>
}
Write descriptions from the perspective of someone consuming this Stack's outputs to help them understand the output's purpose and usage.
Summary
- Data type: String
- Default: None
- Required: No
sensitive
The sensitive argument prevents Terraform from displaying the output value in the HCP Terraform UI and logs.
output "<LABEL>" {
description = "<DESCRIPTION>"
type = <TYPE_CONSTRAINT>
value = <EXPRESSION>
sensitive = <BOOLEAN>
}
When you set sensitive to true, the HCP Terraform UI displays the output as (sensitive value) instead of showing the actual value. Terraform still records sensitive values in state, so anyone with state access can view these values. For more information about safely storing sensitive data, refer to Manage sensitive data.
Summary
- Data type: Boolean
- Default:
false - Required: No
ephemeral
The ephemeral argument excludes the output value from plans and state data, making it available only during runtime.
output "<LABEL>" {
description = "<DESCRIPTION>"
type = <TYPE_CONSTRAINT>
value = <EXPRESSION>
ephemeral = <BOOLEAN>
}
Ephemeral outputs are useful for temporary values like session tokens or short-lived credentials that you don't want to persist in state.
You can only reference ephemeral variables from specific contexts or Terraform throws an error:
- In a managed resource write-only argument
- In an
ephemeralblock - In the
localsblock - In other
variableblocks with theephemeralargument set totrue - In other
outputblocks with theephemeralargument set totrue - Configuring providers in the
providerblock - In provisioner and connection blocks
Summary
- Data type: Boolean
- Default:
false - Required: No
Examples
The following examples demonstrate common use cases for output blocks in component configurations.
Fundamental component output
In the following example, the instance_ip output exposes the private_ip value from the web_server component as a string:
output "instance_ip" {
description = "The private IP address of the web server"
type = string
value = component.web_server.private_ip
}