HashiCorp Terraform Associate (004) · Section 2 · 12% of the exam
Explain how Terraform uses and manages state
One of the objectives of the HashiCorp Certified: Terraform Associate (004) exam, in the section “Terraform fundamentals”. Here is what it covers, the points to remember and a question to try.
What it covers
State maps your configuration to real objects. This lesson explains what terraform.tfstate contains, why Terraform needs it, how plan and apply refresh and update it, why it holds secrets, and which commands inspect or change it safely.
Points to remember
- State binds every resource instance to one real object and is stored by default in
terraform.tfstate(previous copyterraform.tfstate.backup). - The purposes are mapping, metadata (dependencies, provider used), performance and team syncing.
- Terraform refreshes state from real objects before each plan;
-refresh=falseskips this and misses drift. terraform apply -refresh-onlyupdates state only and never changes infrastructure;terraform refreshis deprecated.- Deleting a resource block makes the next plan destroy the object, because state still records it.
Try a question
Using the default local backend, an engineer creates a CLI workspace named staging. Where is its state stored?
- Aterraform.tfstate, overwriting the default workspace's state in the working directory
- B.terraform/staging.tfstate
- Cterraform.tfstate.backup
- Dterraform.tfstate.d/staging/terraform.tfstate in the working directory
Show the answer
D. The default workspace uses terraform.tfstate. Other workspaces get separate files, so the same configuration can manage separate sets of resources.
Written for practice in the style of the exam: never a question from the real exam.
In the course
The lesson How Terraform uses and manages state teaches this objective (about 40 minutes), and 19 practice questions test it. The course has lessons, exam-style questions, timed practice exams and an AI tutor for every objective, and a pass prediction that tells you when you're ready to book.