Terraform State File
Last updated: November 28, 2024In order to track changes in the infrastructure, Terraform uses the so called terraform state file. Usually, this file is created inside the folder where your main terraform file is and it is usually named terraform.tfstate.
When rushing, it is easy to just start and keep the file there, though this comes with some challenges, e.g.:
When rushing, it is easy to just start and keep the file there, though this comes with some challenges, e.g.:
- If you loose this file (gets deleted, or any other way), you loose track of your infrastructure state
- If you are a team of multiple people making changes to the infrastructure, keeping the file locally will make team work challenging
As a best practice, it is recommended to store terraform state file in a shared folder where multiple people can access it. You can do it in a shared network storage or on cloud.
WARNING: Do not commit the terraform state file into your git repository as it contains sensitive information.
Further reading