Terraform Sensitive Output Audit Prompt
Audit a Terraform codebase for leaked secrets — sensitive values landing in outputs, logs, state, or CI artifacts — and apply sensitive flags, ephemeral handling, and redaction to stop exposure.
- Target user
- Security-minded engineers hardening Terraform secret handling
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a security engineer auditing how a Terraform codebase handles secrets. Find every place a sensitive value can leak and prescribe the fix. I will provide: - Modules with variables, outputs, and resources that touch secrets - Backend type and who can read the state - CI configuration and where logs/artifacts are stored - Current secret sources (Vault, SSM, env vars, tfvars) Your job: 1. **Leak surface map** — enumerate the five places secrets leak in Terraform: (a) `output` values without `sensitive = true`, (b) plaintext in state, (c) CI plan logs, (d) `terraform.tfvars` committed to git, (e) provider/resource attributes echoed in plan diffs. Map each to my code. 2. **Sensitive flagging** — find variables and outputs carrying secrets and add `sensitive = true`. Explain that this redacts CLI/log output but does NOT encrypt state, and identify any sensitive value that propagates into a non-sensitive output (which un-redacts it). 3. **Ephemeral & write-only** — where the provider supports it, recommend ephemeral variables/resources and write-only arguments so the secret never persists in state at all. List which of my values qualify. 4. **State exposure** — assess who can read the state backend and whether secrets sit in plaintext there. Recommend encryption at rest, tight IAM, and minimizing secrets stored in state via data sources fetched at apply time. 5. **CI redaction** — check that plan output posted to PRs or logs masks sensitive values, and that artifacts (plan files, JSON state) are not uploaded to world-readable storage. Plan files contain plaintext secrets even when the console hides them. 6. **Source hygiene** — scan for committed tfvars/secrets, recommend `.gitignore` + a pre-commit secret scanner (gitleaks), and a rotation plan for anything already committed to history. 7. **Verification** — commands to confirm a given output is redacted and that no secret appears in `terraform show -json` artifacts. Output as: (a) the leak-surface map with severity, (b) code diffs adding sensitive/ephemeral/write-only handling, (c) the state + CI hardening steps, (d) the source-hygiene + rotation plan, (e) verification commands. Bias toward: keeping secrets out of state entirely, redaction plus encryption, treating plan files as secret material.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Terraform Write-Only Argument Migration Prompt
Migrate existing secret arguments that linger in state (passwords, tokens) to write-only arguments and their `_wo_version` triggers, so sensitive values stop being persisted in the state file.
-
Terraform CI Log Secret Redaction Prompt
Stop secrets from leaking into CI logs and PR plan comments — audit where Terraform exposes sensitive values, enforce `sensitive`, mask provider output, and scrub `terraform show -json` before posting.
-
Terraform Ephemeral & Write-Only Secrets Prompt
Use Terraform 1.10+ ephemeral resources, ephemeral values, and write-only arguments to flow secrets through configuration without ever persisting them in state or plan files.
-
Terraform Secrets & Sensitive Variables Prompt
Manage secrets in Terraform — sensitive flag, ephemeral resources, external secret managers, plan/state masking.
More Terraform prompts & error guides
Browse every Terraform prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.