Terraform Outputs
Output values make information about your infrastructure available after a
terraform apply. They are useful for displaying IP addresses, resource IDs, or any computed value you need for other systems or for a human user.Declaring an Output
Use the
output block with a name and a value expression.output "instance_ip" {
value = aws_instance.web.public_ip
}After applying, Terraform prints the output values.Output Description
Add a description to document the output:
output "instance_ip" {
description = "Public IP address of the web server"
value = aws_instance.web.public_ip
}Sensitive Outputs
Mark an output as sensitive to hide it from logs and CLI output (e.g., for passwords).
output "db_password" {
value = random_password.db.result
sensitive = true
}Using Outputs in Other Configurations
If you use remote state (covered later), you can access outputs from another Terraform configuration using
data.terraform_remote_state.Example: Multiple Outputs
output "web_server_ip" {
value = aws_instance.web.public_ip
}
output "security_group_id" {
value = aws_security_group.web_sg.id
}
output "instance_id" {
value = aws_instance.web.id
}Two Minute Drill
- Outputs expose resource attributes after apply.
- Define with
output "name" { value = expression }. - Add
sensitive = trueto hide values. - Useful for passing information to other Terraform configs or scripts.
Need more clarification?
Drop us an email at career@quipoinfotech.com
