Monday, November 9, 2020

How does Terraform stores state information | Terraform state Best practices

One of the things that Terraform does (and does really well) is “tracks” your infrastructure that you provision. It does this through the means ofstate.

Terraform state is used to reconcile deployed resources with Terraform configurations. State allows Terraform to know what resources to add, update, or delete. 

This state is stored by default in a local file named "terraform.tfstate", but it can also be stored remotely, which works better in a team environment. 

Why state file should not be stored in your local machine?

  • Local state doesn't work well in a team or collaborative environment.
  • Terraform state can include sensitive information.
  • Storing state locally increases the chance of inadvertent deletion.
Terraform State Management Best practices:
1. Never store state file locally. store in remote places such as AWS S3, Azure blob storage.
2. Always create versioning for remote state file incase if you loose your remote state file or file is corrupted.
3. Never make any manual changes to the state file as it is a JSON file can be modified
4. Always create state file per environment
5. Deploy infrastructure changes using CICD tools instead of manually doing it 

Terraform uses this local state to create plans and make changes to your infrastructure. Prior to any operation, Terraform does a refresh to update the state with the real infrastructure.

Terraform state can include sensitive information. Storing state locally increases the chance of inadvertent deletion. Terraform supports the persisting of state in remote storags such Azure Storage or AWS S3 bucket

Please watch the steps in YouTube channel to learn how to store state file in S3 Bucket.


No comments:

Post a Comment

AWS, Azure Cloud and DevOps Coaching Online Classes | Dec 2021 Schedule

Are you in IT? Tired of your work? Are you not able to make any good progress in your career?  Are you not having a job? Looking for a b...