Skip to main content
In this lesson we explain Terraform output variables — the mechanism Terraform uses to expose useful runtime information after resources are created. An output answers a simple question: How do I get values out of Terraform after apply? Common use cases for outputs:
  • Expose values only known after creation (for example, IP addresses or resource IDs).
  • Display operational information such as public IPs, URLs, or connection strings.
  • Pass values to other modules, scripts, or CI/CD pipelines to enable further automation and orchestration.
The image is an infographic explaining output variables, focusing on their roles in exposing values, displaying resource details, and enabling further processing in Terraform.

Example resources

We’ll use a minimal example: an Azure resource group and an Azure public IP. The ip_address attribute is assigned by Azure only after the resource is created — which is exactly why outputs are useful.

Output block structure

An output block provides a name and a value, and may optionally include a description, sensitive, and other arguments. The value is normally a reference to a resource attribute — not a hard-coded literal. General form:
Example — expose the public IP address assigned by Azure:
This value is evaluated after apply because ip_address is assigned dynamically by Azure.

Where to put outputs

Terraform will load outputs from any .tf file in the current working directory (for example, main.tf). As a best practice, keep outputs in a dedicated outputs.tf file for clarity and easier maintenance. Example showing both locations are valid:

Plan and apply behavior

During terraform plan, attributes that Terraform cannot compute until apply are shown as (known after apply). Outputs referencing such attributes will also be reported as (known after apply) in the plan. Example (condensed):

Retrieve outputs

After apply you can fetch outputs at any time:
  • terraform output — lists all outputs
  • terraform output <name> — shows a single output value
  • terraform show — displays the full state; outputs appear in the Outputs section
Examples:
Note: Outputs are stored in the Terraform state. Terraform prints them after apply, and subsequent terraform output reads values from state (not by re-querying the provider).
Outputs are stored in the Terraform state file. If an output contains sensitive information, mark it with sensitive = true to avoid printing it to the CLI by default.
Do not expose secrets via outputs unless absolutely necessary. Use sensitive = true and restrict access to your remote state backend.

Output arguments reference (quick)

Using outputs in a workflow — step-by-step demo

Below is a concise walkthrough to create resources and outputs in a workspace.
  1. Create a new folder (for example, outputs) and add your Terraform configuration.
Example resources: a resource group and a storage account:
  1. (Optional) Target a specific resource for exceptional cases (recovery, incremental testing). Use -target with care — Terraform will warn that the plan may be incomplete.
Example warning the CLI shows when using -target:
  1. Add a public IP resource and create an output for the IP address.
  1. Consult the provider/resource documentation to learn which attributes are exported. For AzureRM azurerm_public_ip the exported attributes include id, ip_address, and (if applicable) fqdn. See the AzureRM docs for details: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/public_ip
This is a screenshot of the AzureRM documentation for Terraform, focusing on the configuration of a public IP resource. It includes parameter options, notes, and attribute references related to the setup.
  1. Create outputs.tf and define the output using the attribute discovered in the docs:
If the output must not be printed to the console (for example, a connection string), mark it as sensitive:
  1. Initialize, plan, and apply:
Condensed apply output:

Common CLI commands

Verification

Cross-check the printed public IP in the Azure Portal: https://portal.azure.com — navigate to the resource group and the Public IP resource to confirm the allocation matches the Terraform output.

Summary

Terraform outputs let you expose runtime values for humans and automation. Use outputs to:
  • Export values only known after creation (IP addresses, IDs, FQDNs).
  • Provide connection details or metadata to scripts and CI/CD pipelines.
  • Keep outputs organized in outputs.tf for clarity.
Always mark secrets with sensitive = true and protect access to your state backend. For more provider-specific exported attributes, consult the provider docs such as the AzureRM azurerm_public_ip resource: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/public_ip.

Watch Video

Practice Lab