Thuta Learning
IntermediateDevOpsintermediate

Outputs

Relax. We'll talk through this in plain words — no textbook voice.

What you'll walk away with

  • Understand Outputs, no intimidation required
  • Get hands-on running terraform commands and HCL code yourself
  • Be ready to apply this concept in a real project right away

Let's think about this for a second

After a resource is created, there are values auto-generated by Terraform/the cloud provider (for example, a server's public IP address, or a database's connection endpoint) — if you want to see these values in the terminal right after apply finishes, use an output block (`output "name" { value = ... }`). Outputs are also widely used to pass data between modules (later lesson) — a parent module can consume a child module's output as its own input.

Let's connect this to a real scenario

If you define `output "server_ip" { value = aws_instance.web.public_ip }`, you'll immediately see `server_ip = "54.123.45.67"` in the terminal after `terraform apply` finishes — no more manually hunting down the IP address in the cloud console just to SSH in. Running the `terraform output` command any time after apply lets you see all output values again.

Let's look at an example

hcl
resource "aws_instance" "web" {
  ami           = "ami-0abcdef1234567890"
  instance_type = "t3.micro"
}

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

output "server_id" {
  value = aws_instance.web.id
}
You should see
$ terraform apply
...
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Outputs:

server_id = "i-0123456789abcdef0"
server_ip = "54.123.45.67"

5-minute try-it

Add 2 output blocks (server_ip, server_id) and apply — then run `terraform output` separately and check the values.

A quick word of caution

Add the `sensitive = true` argument to any sensitive output — Terraform will hide the value in terminal output as `(sensitive value)` (though it still appears in the state file).

Easy traps

  • Not marking an output that holds sensitive data (like a password) with `sensitive = true` — it can end up showing as plain text in the terminal/logs
  • Misspelling a resource's attribute name in an output (worth double-checking against the Registry documentation)

Now try it yourself

Add 2 output blocks (server_ip, server_id) and apply — then run `terraform output` separately and check the values.

You'll know it worked when: $ terraform apply ... Apply complete! Resources: 1 added, 0 changed, 0 destroyed. Outputs: server_id = "i-0123456789abcdef0" server_ip = "54.123.45.67"

Outputs | Thuta Learning