Secrets hardcoded in Terraform files
It's tempting to write a database password or API key straight into a resource argument in a .tf file. That value is then committed to git and also stored, often in plaintext, in Terraform state.
Why it matters
Anyone with the repo (or its history) has the secret, and it can't be rotated without a code change — the same problem as any secret in source.
Terraform state frequently contains the resolved value too, so even a variable can leak if state isn't protected.
How to check for it
- Grep .tf files for password/secret/token/access_key = "..." with a literal value rather than a var or data source.
- SkyShield's app-security scanner flags hardcoded credentials in Terraform as part of its IaC checks.
How to fix it
- Pass secrets as variables sourced from a secret store (Vault, AWS Secrets Manager, SSM) or a data source, never as literals.
- Store state in an encrypted, access-controlled backend, and rotate any secret that was ever committed.
SkyShield checks this automatically
Connect your AWS, Cloudflare, GitHub, GitLab, Hetzner or DigitalOcean account read-only and SkyShield flags this across every account and region, with the fix in plain words — alongside the agent that watches your servers. Start free.
FAQ
- Does using a variable hide the secret?
- It keeps it out of the .tf file, but the resolved value can still land in state — so protect the state backend and prefer a secret manager / data source.