Terraform

What best practices keep Terraform state secure and reliable?

Difficulty: unrated

Source: bregman-arie/devops-exercises by Arie Bregman

Answer

  • Encrypt and version your remote backend (for example aws_s3_bucket_versioning plus SSE-KMS on S3).

  • Enforce locking (DynamoDB, GCS locking, or Terraform Cloud workspaces) and monitor stuck locks.

  • Grant IAM minimum privileges and rotate access keys; automation should assume roles with short-lived credentials.

  • Schedule automated backups of the backend (S3 replication, DynamoDB PITR) and periodically test restores.

  • Document "state owner" responsibility, incident response, and break-glass steps for unlocks or manual edits (should be last resort).