Sensitive Outputs
You'll learn how to hide sensitive information in Terraform outputs using the sensitive flag.
When you output values from your Terraform configuration, they appear in the CLI and are stored in state files. This works great for URLs, resource IDs, or instance names—but what about passwords, API keys, or access tokens? You don't want those printed to your terminal or visible to everyone who can read the apply logs.
Why Mark Outputs as Sensitive?
Think of sensitive outputs like covering a PIN pad at an ATM. The number still exists and gets processed, but it's hidden from casual view. When you mark an output as sensitive, Terraform:
- Hides the value in CLI output (shows
<sensitive>instead) - Prevents accidental exposure in logs or screenshots
- Still stores the value in state (remember: secure your state file!)
- Allows programmatic access for automation that needs it
Using the Sensitive Flag
When declaring an output, add sensitive = true:
output "database_password" {
value = aws_db_instance.main.password
description = "The master password for the database"
sensitive = true
}
Now when you run terraform apply, instead of seeing the actual password, you'll see:
Outputs:
database_password = <sensitive>
The value is still available to other modules or automation tools that consume your outputs—it's just hidden from human-readable displays.
Key Takeaway: Use sensitive = true on outputs containing secrets or credentials to prevent them from appearing in CLI output and logs, while still making them available for programmatic use.