Domain 6 of 8 · Chapter 4 of 4

Manage resource drift and Terraform state

Unlock the complete study guide + 1,040 practice questions across 16 full exams.

Bundled into the existing HashiCorp Certified: Terraform Associate premium course — no separate purchase.

14-day money-back guarantee — no questions asked.

Included in this chapter:

  • State is Terraform's ledger of reality
  • Detecting drift with plan and -refresh-only
  • Accepting drift: apply -refresh-only
  • Refactoring state: mv, rm, moved, removed
  • Exam pattern recognition

State-maintenance operations: what each one touches

OperationWhat it changes in stateTouches real infrastructure?Reviewed via plan/apply?
plan -refresh-onlyNothing; reports drift onlyNoRead-only preview
apply -refresh-onlyRecords observed driftNoYes, with approval
state mvRebinds object to a new addressNoNo, immediate
state rmRemoves the object's bindingNoNo, immediate
moved blockRebinds address, like state mvNoYes
removed blockRemoves binding, like state rmDestroys unless destroy=falseYes

Decision tree

Did the object change outside Terraform? Inspect or record the drift? Move an address or stop managing? plan -refresh-only inspect only apply -refresh-only record drift moved block or state mv removed block or state rm Yes: drift No: refactor inspect record rename / move forget

Cheat sheet

  • Drift is state diverging from real infrastructure
  • plan and apply refresh state in memory to detect drift
  • plan -refresh-only shows drift without config changes
  • apply -refresh-only updates state to match reality
  • terraform refresh is deprecated
  • -refresh-only replaced the refresh subcommand
  • state rm stops managing a resource without destroying it
  • state mv rebinds an object to a new address
  • moved block is the declarative alternative to state mv
  • removed block forgets resources via plan/apply

Unlock with Premium — includes all practice exams and the complete study guide.

References

  1. Manage Resource Drift
  2. Command: plan
  3. Command: refresh
  4. Command: state mv
  5. Refactoring with moved Blocks
  6. Command: state rm
  7. The removed Block
  8. Remove a Resource from State