Understanding the Terraform state
Note
The code for this section is under chap02/statefile
in the GitHub repo of this book.
Understanding the concept of state is essential to master Terraform. A Terraform configuration is a declaration of the desired state—that is, you specify how you want things to be. Terraform’s job is to bring the current state to the desired state.
So, when you started, you specified in your configuration—that is, the collection of .tf
files—that you would like to have one compute instance. Then, when you run terraform apply
, Terraform takes the necessary actions to bring the resource address into the desired state. Since you didn’t have any compute instance as specified in your configuration file, Terraform created one.
To start this section, run Terraform by executing the following two commands. This provisions the infrastructure where we left off in the last chapter:
$ terraform init $ terraform apply
Now...