Skip to main content

Output Value

A Terraform output value exposes selected attributes of your infrastructure after an apply, such as an IP address or bucket name. Outputs print in the terminal and can be read by parent modules, scripts, and other configurations.

What Is an Output Value?

An output is how a configuration or module returns data, like a function returning a value.

HCL
output "s3_bucket_name" {
description = "Bucket name for APP_DATA_BUCKET"
value = aws_s3_bucket.app_data.id
}
Bash
terraform output -raw s3_bucket_name # plain value for scripts
terraform output -json # machine-readable

Parent modules read child outputs as module.NAME.OUTPUT. Other configurations can read root outputs through terraform_remote_state.

Common Mistake

Forgetting sensitive = true on an output that holds a secret. It then prints in CI logs, and even sensitive outputs remain in plaintext in state.

Frequently Asked Questions

What are outputs used for besides printing?

They are a module's interface. Parents read them, scripts read them with terraform output -json, and other configurations read root outputs through terraform_remote_state.

Can terraform_remote_state read any value from another state?

No. It exposes only root module outputs, so re-export child module values as root outputs.

Found a mistake, an outdated step or a broken link?