DEV Community

1suleyman
1suleyman

Posted on

🧾 What Are Terraform Output Values? (And Why They’re Like Receipts for Your Cloud Builds)

Hey everyone 👋

If you're learning Terraform or building anything in the cloud, you've probably seen something called an output block. At first, I had no clue what it was for. Was it logging? Debugging? Something I could skip?

Turns out, output values are one of the handiest features in Terraform — especially if you're working across multiple teams, modules, or projects.

Let me break it down the way I wish someone had done for me 👇


🧸 Think of It Like a Receipt (After a Cloud Purchase)

Let’s say you order something online — a laptop, a desk, a new router.

Once it arrives, you don’t just say “cool” and walk away. You check the delivery receipt. What’s the tracking number? When did it arrive? What’s the address it shipped to?

That’s exactly what output values do in Terraform.

After Terraform builds your infrastructure — whether it’s an EC2 instance, a VPC, or an Elastic IP — you can ask it to show you specific information about what it created.


📦 Why Use Output Values?

When you run terraform apply, Terraform builds your infrastructure — but it doesn’t show you all the details by default.

With output values, you can:

✅ See useful info like IP addresses, DNS names, URLs, IDs — right in your terminal
🔁 Pass values between projects or modules
🧪 Test your infrastructure with real data
📥 Save time by skipping manual console checks


⚙️ Real Example: Outputting a Public IP

Let’s say you create an Elastic IP in Terraform like this:

resource "aws_eip" "lb" {
  vpc = true
}
Enter fullscreen mode Exit fullscreen mode

You want the public IP address printed after deployment. Just add this:

output "public-ip" {
  value = aws_eip.lb.public_ip
}
Enter fullscreen mode Exit fullscreen mode

Now when you run terraform apply, Terraform shows:

Outputs:

public-ip = "3.88.123.45"
Enter fullscreen mode Exit fullscreen mode

Instant visibility 🙌 No console needed.


💥 You Can Even Customize It

Let’s say your app runs on port 8080 and you want a full URL:

output "web-url" {
  value = "https://${aws_eip.lb.public_ip}:8080"
}
Enter fullscreen mode Exit fullscreen mode

Boom. You now get:

web-url = "https://3.88.123.45:8080"
Enter fullscreen mode Exit fullscreen mode

One command, and you have a ready-to-use URL. Great for testing, automation, or just sharing with your team.


🤹‍♀️ Bonus: Show All Attributes at Once

Don’t want to specify which field to output? Just pass the whole resource:

output "eip-details" {
  value = aws_eip.lb
}
Enter fullscreen mode Exit fullscreen mode

This gives you all available info — public DNS, domain, ID, and more.


🔗 Sharing Outputs Between Projects

Here’s where it gets even cooler.

Let’s say you have:

🅰️ Project A: creates an Elastic IP
🅱️ Project B: needs that IP to configure a load balancer

Project A can output the IP, and Project B can read it — either manually or programmatically through Terraform's remote state.

💡 Think of it like leaving a sticky note: “Hey, the IP you need is 3.88.123.45.” No more guessing or hardcoding values.


🧠 What About the State File?

All output values are saved in your terraform.tfstate file. Here’s how it might look:

"outputs": {
  "public-ip": {
    "value": "3.88.123.45"
  }
}
Enter fullscreen mode Exit fullscreen mode

That’s how Terraform (or another project) can read it later — as long as it has access to that state file.


🎯 Key Takeaways

✅ Benefit 💡 Why It Matters
Show key info Get real values (IP, URL, DNS) in your CLI
Save time No need to log into the AWS Console
Enable automation Pass values between Terraform projects or CI/CD pipelines
Boost collaboration Let other modules or teams consume your outputs
Add flexibility Customize URLs, combine attributes, or show full resources

🧩 Final Thoughts

Terraform outputs might seem small at first, but they’re super powerful once you start using them.

They help you:

  • Avoid console rabbit holes
  • Speed up testing and deployment
  • Connect infrastructure across modules and projects

If you're building anything cloud-based with Terraform, learning how to use output values is 100% worth it.

Are you using outputs in an interesting way? Got a cool trick to share? Drop it in the comments or hit me up on LinkedIn — always happy to learn from others building in the cloud ☁️🔁

Top comments (0)