0
0
TerraformConceptBeginner · 3 min read

What is Output in Terraform: Explanation and Example

In Terraform, output is a way to show useful information after your infrastructure is created or changed. It lets you see values like IP addresses or resource IDs that your configuration produces.
⚙️

How It Works

Think of Terraform like a recipe for building your cloud setup. After following the recipe, you might want to know some details about what was made, like the address of a server or the name of a storage bucket. output in Terraform is like a note you leave at the end of the recipe that tells you these important details.

When you run Terraform commands to create or update your infrastructure, the output values are collected and shown to you. This helps you use those values later, for example, to connect to a server or pass information to another tool.

💻

Example

This example shows how to define an output that displays the public IP address of a created server.

terraform
resource "aws_instance" "example" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "t2.micro"
}

output "instance_ip" {
  value       = aws_instance.example.public_ip
  description = "The public IP address of the example instance"
}
Output
instance_ip = "54.123.45.67"
🎯

When to Use

Use output when you want to see or share important information about your infrastructure after Terraform runs. For example:

  • Showing IP addresses or URLs to connect to servers.
  • Passing resource IDs to other Terraform configurations or automation scripts.
  • Debugging by checking values generated during deployment.

This helps teams communicate and automate better by making key details easy to access.

Key Points

  • Outputs display useful info after Terraform applies changes.
  • They can include resource attributes like IPs, IDs, or names.
  • Outputs help connect Terraform with other tools or manual steps.
  • You define outputs in your Terraform files using the output block.

Key Takeaways

Terraform outputs show important info after infrastructure changes.
Define outputs using the output block with a value to display.
Outputs help share resource details like IPs or IDs with others.
Use outputs to connect Terraform with other tools or scripts.