Member-only story
Effective Ways of Managing Your Terraform State
Collaboration in your team with remote-state back ends

Terraform is one of the most popular infrastructure as code (IaC) tools available. It isn’t only one of the most active open-source projects, but it’s also cutting edge to the point that whenever AWS releases a new service, Terraform has a resource ready even before AWS’s CloudFormation.
Terraform is a declarative IaC software. That means admins declare what infrastructure they want, instead of worrying about the nitty-gritty of writing scripts to provision them. That makes Terraform extremely simple to learn and manage.
It’s incredibly flexible and supports multiple cloud providers. It’s extendable to the point that any cloud provider can create its provider plugins and release it to its users. The users can then use HashiCorp Configuration Language (HCL) scripts for templating their infrastructure deployments and automating infrastructure like never before.
How Does Terraform Work?
As Terraform is a declarative IaC tool, it needs to store and maintain a state. That’s necessary to understand the differences between the expected and the actual configuration. One might argue that Terraform might query the cloud services to match with the expected setting, but there’s a catch here.
- How would Terraform know that someone has removed a configuration from the template it had applied before?
- How would Terraform understand if a cloud resource is dependent upon another? For example, if you specified an explicit dependency of an S3 bucket on an EC2 instance, Terraform needs to know it can’t delete the S3 bucket without deleting the EC2 instance.
- If multiple people are changing a configuration, how would Terraform understand which one was applied before, and how will it keep track of various versions? There might be situations in which two people want to apply changes at the same time in a team. Terraform locks the state so only one person at a time can change the state.
- The Terraform state also helps improve performance, as it acts as a local version of the applied configuration, and it helps speed up the plan.
terraform plan
runs refreshes…