sensitive = true. It also clarifies what sensitivity protects and what it does not, and provides best practices for secure secret management.
Problem
If you pass a secret (e.g., an RDS password) into Terraform as a plain string variable, Terraform will interpolate it into resources — andterraform plan will print the secret in the plan output. That output can end up in CI logs, terminal history, screenshots, or other stored artifacts.
Vulnerable example:
terraform plan, the secret can appear in plaintext:
Solution — mark variables (and outputs) as sensitive
Mark the variable withsensitive = true to redact the value from console output and logs. This does not change how providers receive values; it only prevents display in Terraform CLI output and log captures.
Fixed example:
terraform plan shows a redacted value:
What sensitive variables/outputs protect — and what they don’t
Use the table below to quickly see the protection scope ofsensitive = true.
| Protects | Does NOT protect |
|---|---|
Hides values in terraform plan and terraform apply console output | Does not encrypt secrets in the Terraform state file |
| Prevents secrets appearing in CLI logs and printed error messages | Does not prevent transmission of secrets to providers during apply |
Works for both variables and outputs (use sensitive = true on outputs) | Is masking/redaction for display only — not cryptographic protection |

Marking variables and outputs as
sensitive is primarily about reducing accidental exposure (logs, console output, error messages). It is not a substitute for proper state encryption and secure secret management.Terraform state files may contain secret values in plaintext. Use remote state backends with encryption at rest, restrict access to state, and consider additional secret-management patterns (e.g., retrieving credentials from a secrets manager at apply time).
Sensitive outputs
You can mark outputs as sensitive the same way as variables. Example:- Interactive console: a non-sensitive output like
database_endpointprints normally afterterraform apply. A sensitive output such asdatabase_passwordis redacted as(sensitive value)in the printed outputs. - Programmatic consumption: automation can still retrieve sensitive outputs. For example:
terraform output -raw database_passwordterraform output -json
Best practices and recommendations
- Do:
- Mark variables and outputs containing secrets as
sensitive = true. - Store state in a remote backend with encryption at rest and strict ACLs (e.g., Terraform Cloud, S3 with SSE and proper IAM policies).
- Use dedicated secret managers for long-lived credentials (e.g., AWS Secrets Manager, HashiCorp Vault) and fetch secrets at apply time.
- Limit access to CI logs and workspace artifacts that may contain plan outputs.
- Mark variables and outputs containing secrets as
- Avoid:
- Hardcoding secrets in Terraform files or checked-in variable files.
- Relying on
sensitiveas a replacement for encrypted state or robust secret management.
Useful links and references
- Terraform: Sensitive variables — https://www.terraform.io/language/values/variables#sensitive-variables
- Terraform: Outputs — https://www.terraform.io/cli/commands/output
- Terraform: Remote state — https://www.terraform.io/language/state/remote
Summary
- Use
sensitive = truefor variables and outputs to prevent secrets from appearing in CLI output and logs. - Remember that
sensitiveis redaction/masking, not encryption — the state file and provider transmissions may still contain plaintext secrets. - Combine
sensitivewith secure remote state backends, strict access controls, and a secrets manager for layered protection.