HashiCorp Terraform Associate (004) · Section 6 · 10% of the exam
Configure remote state using the backend block
One of the objectives of the HashiCorp Certified: Terraform Associate (004) exam, in the section “Terraform state management”. Here is what it covers, the points to remember and a question to try.
What it covers
Terraform keeps a state file that maps your configuration to real objects. This lesson covers the default local backend, how state locking prevents two runs from writing at once, and how to move state to a remote backend with the backend block, partial configuration and terraform init.
Points to remember
- With no backend or cloud block, Terraform uses the local backend and stores state in terraform.tfstate in the working directory.
- The local backend keeps the previous state in terraform.tfstate.backup and non-default workspaces under terraform.tfstate.d.
- Terraform locks state automatically for operations that could write it, if the backend supports locking.
- -lock-timeout waits for a lock; -lock=false skips locking and is not recommended; force-unlock LOCK_ID releases a stale lock.
- S3 native locking is use_lockfile = true (a .tflock object); DynamoDB locking is deprecated.
Try a question
The networking team's root module defines output "subnet_ids". Another team wants to use those IDs and has read access to the remote state. Which feature reads them?
- AThe
terraform_remote_statedata source, which exposes root-module outputs - B
terraform state pull, parsed in alocal-execprovisioner - CThe
backendblock withdata = trueset - D
terraform importof the subnets into the second configuration as managed resources
Show the answer
A. The terraform_remote_state data source reads the latest state snapshot of another configuration and exposes only its root-level output values. Other approaches include reading the real objects through provider data sources.
Written for practice in the style of the exam: never a question from the real exam.
In the course
The lesson Local backend, state locking and remote state teaches this objective (about 40 minutes), and 24 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.