terraform state
Terraform uses a state file to track what it has deployed and what resources it is managing. The state file is essential as it contains a record of all the infrastructure Terraform is maintaining, and if you lose it, Terraform will lose track of what it has done so far and start treating resources as if they are new and need to be created again. Therefore, you should protect your state as you would protect code.
Terraform stores state in backends. By default, Terraform stores the state file as a file called terraform.tfstate
within the workspace
directory, which is called the local backend. However, that is not one of the best ways of managing the state. There are several reasons why you should not store state in a local system:
- Multiple admins cannot work on the same infrastructure if the state file is stored within someone's local directory.
- Local workstations are not backed up, and therefore even if you have a single admin doing the job, the risk...