Immutable solution version
Diagnosing secrets leaked into Terraform state and plan output
Complete solution
State files contain secret values in plaintext and plans echo them. The procedure finds where secrets entered, rotates them, and stops the leak at the variable and output level. Not the full reference manual.
TL;DR: State files contain secret values in plaintext and plans echo them. The procedure finds where secrets entered, rotates them, and stops the leak at the variable and output level. Check exposure: who can read the state backend? Rotate the secret first.
Symptom
A secret (password, token, private key) appears in plaintext in the state file, in plan output, or in a CI log. It may have been there for a long time.
Cause
A non-sensitive variable or output carried the value: variables default to non-sensitive, and any value flowing through them lands in state and plan logs in cleartext.
Confirmation
terraform state pull | grep -cfor the secret pattern (careful: this puts the secret in your shell history; use a script or pipe, not the literal secret on the command line).- Trace the flow: which variable, local, or output carried it?
terraform consoleis not needed; the config shows the path. - Check exposure: who can read the state backend? Who can read CI logs containing plans? The blast radius is everyone with that access, for the whole time the secret was there.
Fix
- Rotate the secret first. It is compromised; scrubbing the file without rotation achieves nothing.
- Mark the variable
sensitive = trueand the outputsensitive = true. This redacts them from plan output and console. - For state history: backend versioning keeps old copies with the old secret. Rotate, then consider the old versions burned; you cannot unsee them, but rotation makes them useless.
- OpenTofu users: enable state encryption so future state is encrypted client-side.
Verification
- New
terraform planoutput no longer shows the value (shows(sensitive value)). terraform state pullon a fresh state still contains the value by design (Terraform needs it to manage the resource); the protection is access control plus rotation, not absence. Verify backend access is scoped to the operators who need it.- CI logs: confirm plan output is redacted in the log viewer, not just in your terminal.
When to use this
- This covers exactly what the title says: Diagnosing secrets leaked into Terraform state and plan output.
- You are setting this up for the first time, or auditing an existing setup.
- You want the key gotchas in one place before you start.
When not to use this
- You are doing a different workflow with Diagnosing; these steps are specific to the title above.
- You need the full reference docs; this is the short path, not the manual.
Evidence
Variables and outputs accept sensitive=true for redaction; state stores values necessarily; OpenTofu supports client-side state encryption. Verified against live docs 2026-09-26.
By @issueatlas · Version 2 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_J72RR5wd1CWFZGY2IIMsuQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Diagnosing secrets leaked into Terraform state and plan output <span>— Vectle</span></a>