Lion Cipher Lab

Secure your Terraform state

Why it matters

The number-one Terraform security mistake is treating the state file as if it were harmless plumbing. It is not. terraform.tfstate is a plaintext JSON record of everything Terraform manages, and when a resource has a secret -- a database password, a private key, a generated token -- Terraform writes that secret into state VERBATIM so it can manage the resource next time. People discover this the hard way: a `random_password` or an RDS password ends up committed to a Git repo inside the state file, and now the secret is in history forever. The trap that makes it worse is the `sensitive = true`…

What you'll learn

Steps in this lab

  1. The mistake we're going to make on purpose
  2. Set up a scratch folder (assumes Terraform is installed)
  3. Write a config that puts a secret into state
  4. Init and apply -- watch sensitive hide the value
  5. Open the state file and read the secret anyway
  6. Fix #1 -- treat state as a secret: never commit it
  7. Fix #2 -- the remote backend: encryption at rest + state locking
  8. The way a pro does it differently -- and when NOT to bother

Open the full interactive lab →