IaC Secrets Management Strategy Prompt
Design how secrets flow through IaC across tools — keep them out of code and state, inject at deploy/runtime via a secrets manager, and rotate without manual re-deploys.
- Target user
- Platform and security engineers handling secrets in IaC
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a security-minded platform engineer who has cleaned up secrets accidentally committed to git, leaked in Terraform state, and printed in CI logs.
I will provide:
- IaC tools in use (Terraform, Pulumi, Helm, Ansible, CloudFormation)
- Where secrets live today and where they need to land (env vars, files, K8s secrets, cloud resources)
- Available secrets backend (Vault, AWS/GCP/Azure secrets manager, SOPS)
- Rotation and compliance requirements
Your job:
1. **The three leak points** — explain where IaC secrets leak: (a) plaintext in code/git, (b) plaintext in state files, (c) CI logs / plan output. Your design must close all three.
2. **Reference, don't embed** — use dynamic references so the secret value never enters code: CloudFormation `{{resolve:secretsmanager:...}}`, Terraform `data` from the secrets manager (NOT a `variable` with a default), Helm + External Secrets Operator, SOPS-encrypted files decrypted at apply.
3. **State protection** — when a secret unavoidably lands in state (some resources require it), encrypt state at rest, restrict backend access, and treat state as a secret. Prefer resources/providers that keep secrets write-only.
4. **Injection timing** — decide per secret: bake at deploy (config-mgmt pulls it) vs inject at runtime (sidecar/CSI driver/init container fetches it). Default to runtime injection so rotation doesn't require redeploy.
5. **Rotation** — design for it: short-lived dynamic credentials (Vault DB engine, cloud IAM roles) over static long-lived secrets. Show how the app picks up a rotated secret without a redeploy.
6. **Guardrails** — pre-commit secret scanning (gitleaks/trufflehog), CI secret masking, and a policy check that fails PRs introducing plaintext secrets.
7. **Break-glass** — how to retrieve/rotate emergency credentials with an audit trail.
Output as: (a) per-tool reference pattern, (b) the state-protection plan, (c) the runtime-injection design, (d) the rotation approach, (e) the pre-commit + CI scanning setup, (f) the single highest-risk leak in this setup right now.
Bias toward: secrets never in code or git, runtime injection over baking, and short-lived dynamic credentials over static ones.
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
-
Ansible Vault Rekey and Rotation Workflow Prompt
Design a safe ansible-vault rekey workflow that rotates the vault password and the underlying secrets across multiple environments without breaking running playbooks or CI.
-
CloudFormation Dynamic References for SSM & Secrets Manager Prompt
Replace hardcoded secrets and config in CloudFormation templates with resolve dynamic references to SSM Parameter Store and Secrets Manager, including versioning, rotation, and no-echo handling.
-
Pulumi Secrets Provider Migration & Key Rotation Prompt
Migrate a Pulumi stack's secrets provider (passphrase to KMS/Vault or between clouds) and rotate the encryption key so all encrypted config and state secrets are re-wrapped without leaking plaintext.
-
Packer Build Provenance & Image Signing Prompt
Add provenance, SBOM generation, and signing to a Packer image pipeline so every golden image is attributable, scannable, and verifiable before it ships to production.
More Infrastructure as Code prompts & error guides
Browse every Infrastructure as Code 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.