Terraform

Mention some best practices related to tfstate

Difficulty: unrated

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

Answer

  • Don't edit it manually. tfstate was designed to be manipulated by terraform and not by users directly.

  • Store it in secured location (since it can include credentials and sensitive data in general).

  • Backup it regularly so you can roll-back easily when needed.

  • Store it in remote shared storage. This is especially needed when working in a team and the state can be updated by any of the team members.

  • Enabled versioning if the storage where you store the state file, supports it. Versioning is great for backups and roll-backs in case of an issue.

  • Designate "state owners" who review access, rotate credentials, and execute migrations.

  • Keep .tfstate files and the .terraform/ directory out of version control (.gitignore) and encrypt any ad-hoc backups.