Chapter 6 of 8 · HashiCorp Terraform Associate 004

Terraform State Management

The local backend, state locking, remote backends and handling resource drift.

  • 2topics
  • 10 minfast track
  • 1diagrams and exhibits

Topics in this chapter

Take them in order, or jump to the one you need.

  1. 1Local Backend and State LockingTerraform Associate 004: the local backend, terraform.tfstate and its backup, CLI workspaces on disk, automatic state locking and…Diagram5 min
  2. 2Remote Backends and Resource DriftTerraform Associate 004: configure a remote backend, partial configuration, migrate state, detect drift with refresh-only, use…5 min

About this chapter

What this chapter covers

Terraform state management covers where Terraform keeps its state file and how that file stays safe and accurate. State maps each resource in your configuration to a real object, so losing it, corrupting it or letting two people write it at once causes real damage.

The chapter has two parts: the local backend and state locking, then remote state configured with the backend block and the tools for handling drift and refactoring state (refresh-only mode, moved and removed blocks, and the state commands).

Questions are single-answer, multiple-answer ("Pick the 2 correct responses below") and true or false statements, mostly direct recall of commands and behavior plus short HCL snippets that open "Consider the following configuration snippet:". There are no exhibits.

How the topics fit together

Local backendterraform.tfstate on diskState lockingone writer at a timeRemote backendshared and locked stateDrift and refactoringrefresh only, moved, removed

Every configuration starts on the local backend. When a team shares the work, the state moves to a remote backend that supports locking, and from then on you keep state and reality in step.

  • Local backend questions ask where state is written by default and what the backup file is.
  • Locking questions ask when locking happens, which flag disables it and when to use force unlock.
  • Backend block questions ask what the block may contain, how partial configuration works and what to run after a change.
  • Drift questions ask how plan and apply detect changes made outside Terraform and how refresh only mode updates state.
  • Refactoring questions ask how to rename or stop managing a resource without destroying it.
Exam tip

Most state questions turn on one word. "Rename" points to a moved block, "stop managing" points to a removed block or terraform state rm, and "changed outside Terraform" points to refresh only mode.

How to use these pages

Each topic page has the same shape, so you can skim for what you need.

  • What it is: the idea in plain words.
  • How it works: the mechanism, with tables and examples.
  • What to remember for the exam: the facts to memorize and how questions are phrased.
  • Common mistakes: the classic traps.
  • Check yourself: three questions to test your understanding.

Ready for more practice?

The full HashiCorp Terraform Associate 004 question bank has 600 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by HashiCorp. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.