Course contentsShow
← Cloud and Infrastructure
Lesson 765 of 2,98914. Terraform FundamentalsFree lesson

Output Value Syntax and Usage

Declare output blocks to return resource attributes and computed values.

Output Value Syntax and Usage

You'll learn how to declare output blocks in Terraform to expose resource attributes and computed values after infrastructure provisioning.

What Are Output Values?

Outputs are Terraform's way of saying "here's the information you care about" after creating or updating infrastructure. Think of them like a function's return value—they let you capture specific details from your resources and display them or pass them to other configurations.

After Terraform finishes applying changes, outputs appear in the terminal and can be queried later. They're essential for extracting dynamic information like IP addresses, database endpoints, or resource IDs that you don't know until after creation.

Basic Output Syntax

An output block follows this structure:

output "output_name" {
  value       = <expression>
  description = "Human-readable explanation"
}

Example:

output "instance_ip" {
  value       = aws_instance.web.public_ip
  description = "Public IP address of the web server"
}

The value argument is required and can reference resource attributes, variables, or any valid expression. The description is optional but highly recommended for documentation.

Common Patterns

Reference resource attributes directly:

output "bucket_arn" {
  value = aws_s3_bucket.data.arn
}

Combine multiple values:

output "connection_string" {
  value = "https://${aws_instance.web.public_ip}:443"
}

Return complex types:

output "server_details" {
  value = {
    ip   = aws_instance.web.public_ip
    name = aws_instance.web.tags["Name"]
  }
}

Key Takeaway: Output blocks extract and display important information from your infrastructure by declaring a name and value expression, making dynamic resource details accessible after provisioning completes.