Sensitive Outputs
Crumb now has a database, and its password is generated by Terraform with a random_password resource. You want to output it so the app can use it, but you do not want it printed into every CI log. That is what sensitive outputs are for, and it matters to know exactly how far they go.
The rule
sensitive hides it from the screen, not from the state.
output "db_password" {
value = random_password.db.result
description = "Password for Crumb's orders database"
sensitive = true
}With sensitive = true:
- plan shows the value as
(sensitive value), and the outputs printed after apply show<sensitive>. terraform outputwith no name lists it asdb_password = <sensitive>.
What it does not do:
- State still stores it in plain text. Anyone who can read the state file can read the password.
- Asking for it by name reveals it.
terraform output db_password,terraform output -raw db_passwordandterraform output -jsonall print the real value. That is on purpose: scripts need it.
Sensitivity also spreads. If an output's value comes from something already sensitive, such as a variable marked sensitive = true, Terraform refuses to plan until the output is marked sensitive too:
Error: Output refers to sensitive valuesThat error is a guard rail, not a bug. Add sensitive = true, or rethink whether the value should be an output at all.
The shortcut
Picture two doors. The screen door (plan, apply, the output list) is closed by sensitive = true. The state door stays open, so it must be locked separately: a remote backend with encryption and restricted access, or better, a secrets manager so the value never needs to leave the cloud.
Mark it
Add
sensitive = trueto thedb_passwordoutput. CI logs now show(sensitive value).
The trap: believing sensitive means encrypted. It is a display filter.
Drills
Answer fast — trust the rule.
What does sensitive = true on an output change?
Where is a sensitive output's value still readable in plain text?
What does terraform output -raw db_password print for a sensitive output?
An output's value comes from a sensitive variable, and the output has no sensitive setting. What happens?
Remember
sensitive = truehides values from plan, apply and the output list.- Shortcut: it closes the screen door; lock the state door separately.
- Trap: sensitive is not encryption, and naming the output prints it.
