Table of Contents
- Defining an Output Variable
- Generic Output Syntax
- Output Block Arguments
- Complete Example
- Viewing Outputs
- Use Cases
- Links and References
Defining an Output Variable
Use theoutput block with a unique name and the value argument set to the expression you want to expose. You can also include optional arguments like description and sensitive:
Output names must be unique within a module. Use descriptive names to make them easy to reference in other modules or scripts.
Generic Output Syntax
Below is the general form of an output block in OpenTofu:- NAME: The identifier for this output.
- EXPRESSION: Any valid expression or reference, such as
aws_instance.foo.id. - description: A human-readable summary (optional).
- sensitive: When set to
true, the value is omitted from CLI output (optional).
Output Block Arguments
| Argument | Description | Required |
|---|---|---|
| value | Expression or reference whose result you want to expose. | Yes |
| description | A short human-readable explanation. | No |
| sensitive | Hides the value in CLI output when set to true. | No |
Mark any output containing secrets or credentials as
sensitive = true to prevent leaking them in logs or console output.Complete Example
This minimal configuration creates an EC2 instance and then outputs its public IPv4 address:Viewing Outputs
After runningtofu apply, OpenTofu automatically displays all configured outputs:
Use Cases
- Quickly inspect provisioned resource attributes on-screen.
- Pass output values into other IaC tools, ad-hoc scripts, Ansible playbooks, or testing frameworks.
- Expose dynamic data for remote execution contexts or CI/CD pipelines.