Introducing the Terraform backend
In this section, we are going to talk about the Terraform state file and the Terraform backend. As you know, Terraform follows a desired state configuration model where you describe the environment you would like to build using declarative code and Terraform attempts to make that desired state a reality. A critical component of the desired state model is mapping what currently exists in the environment and what is expressed in the declarative code. Terraform tracks this mapping through a JSON formatted data structure called a state file. We are going to look at where the Terraform state file can be stored, how it can be configured and accessed, and what the best practices for keeping a Terraform tfstate
file are.
Terraform state
You are already aware of when you write the Terraform configuration file and how while executing terraform init
, plan
, and apply
, it is used to generate a state file that stores information about your complete infrastructure...