Skip to main content
Output variables make it easy to expose values from your OpenTofu configuration—such as resource attributes—to users, scripts, or other tools. In this guide, you’ll learn how to define, view, and leverage output variables effectively.

Table of Contents


Defining an Output Variable

Use the output 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

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 running tofu apply, OpenTofu automatically displays all configured outputs:
You can also list or fetch outputs at any time:

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.

Watch Video