What if your secret keys were visible to everyone by accident? Sensitive outputs stop that from happening.
Why Sensitive output values in Terraform? - Purpose & Use Cases
Start learning this pattern below
Jump into concepts and practice - no test required
Imagine you manually write down passwords or secret keys on paper every time you set up cloud resources. You share these notes with your team via email or chat without any protection.
This manual way is risky and slow. Secrets can leak easily, causing security breaches. You might forget to remove sensitive info from logs or outputs, exposing your data to anyone who sees them.
Using sensitive output values in Terraform hides secret information automatically. It prevents accidental exposure in logs or command outputs, keeping your secrets safe while still letting your infrastructure work smoothly.
output "db_password" {
value = aws_db_instance.example.password
}output "db_password" {
value = aws_db_instance.example.password
sensitive = true
}You can safely share infrastructure details without risking secret leaks, making teamwork secure and efficient.
A team deploying a database can output the password as sensitive, so developers get the info they need without exposing it in logs or terminal screens.
Manual sharing of secrets is risky and error-prone.
Sensitive outputs hide secrets automatically in Terraform.
This keeps your infrastructure secure and your team confident.
Practice
sensitive = true in Terraform?Solution
Step 1: Understand the role of sensitive outputs
Marking an output as sensitive hides it from the normal Terraform output display to protect secrets.Step 2: Clarify what sensitive does not do
Sensitive does not make outputs public, increase size, or encrypt state automatically.Final Answer:
To hide the output value from the standard Terraform output display -> Option AQuick Check:
sensitive output hides value [OK]
- Thinking sensitive makes output public
- Assuming sensitive encrypts state file
- Believing sensitive increases output size
Solution
Step 1: Recall Terraform block syntax
Terraform blocks use new lines or spaces between arguments without semicolons or commas.Step 2: Identify correct syntax for sensitive output
The correct syntax placessensitive = trueon a new line inside the output block without semicolons or commas.Final Answer:
output "db_password" { value = var.db_password sensitive = true } -> Option AQuick Check:
Terraform blocks use new lines, no semicolons [OK]
- Using semicolons inside blocks
- Using commas between arguments
- Placing sensitive outside the output block
output "api_key" {
value = var.api_key
sensitive = true
}
What will Terraform display when you run terraform output?Solution
Step 1: Understand sensitive output display behavior
Terraform replaces sensitive output values with<sensitive>to avoid showing secrets.Step 2: Confirm output command behavior
Runningterraform outputshows<sensitive>for sensitive outputs, not the real value or errors.Final Answer:
<sensitive> placeholder instead of the value -> Option DQuick Check:
sensitive outputs show <sensitive> [OK]
- Expecting actual secret value to display
- Thinking terraform throws error for sensitive outputs
- Assuming no output is shown at all
output "admin_password" {
value = var.admin_password
sensitive = "true"
}
Terraform gives an error. What is the problem?Solution
Step 1: Check the sensitive attribute type
The sensitive attribute expects a boolean (true/false), not a string with quotes.Step 2: Identify the error cause
Using quotes around true makes it a string, causing Terraform syntax error.Final Answer:
The sensitive attribute must be a boolean, not a string -> Option BQuick Check:
sensitive = true (no quotes) [OK]
- Putting quotes around boolean true/false
- Adding commas inside blocks
- Misnaming output blocks
Solution
Step 1: Protect password in output
Marking output as sensitive hides it from console output, preventing accidental exposure.Step 2: Enable programmatic access
Usingterraform output -jsonallows other configs or scripts to read the secret safely without showing it on screen.Final Answer:
Declare output with sensitive = true and use terraform output -json to pass value programmatically -> Option CQuick Check:
Use sensitive output + json output for safe secret sharing [OK]
- Printing secrets openly in outputs
- Hardcoding secrets in configs
- Ignoring sensitive flag for secrets
