Bitzu

Terraform Associate 004 ยท Maintaining infrastructure

Moving and removing state entries

terraform state mv and rm, moved blocks for refactoring, removed block, effects on real infrastructure (7b).

Key points

  • terraform state mv SOURCE DESTINATION renames an entry in state so a rename does not become destroy-and-create. terraform state rm ADDRESS makes Terraform forget an object; the real object keeps running.
  • Declarative alternatives go through plan and review: a moved block (from, to) for renames and a removed block (from, with lifecycle destroy = false) to stop managing without destroying.

Source: https://developer.hashicorp.com/terraform/cli/commands/state/mv

Practice questions

Single choice

What happens to the real object when you run terraform state rm on it?

  1. It keeps existing but Terraform no longer manages it
  2. It is destroyed immediately
  3. It is renamed in the cloud account
  4. It is replaced on the next apply
Show answer

Answer: A. It keeps existing but Terraform no longer manages it

state rm only deletes Terraform's record. Destruction would need a destroy, and nothing renames or replaces the object.

Select all that apply

Which statements about the removed block are true?

  1. from is required and holds the address to remove
  2. lifecycle with destroy = false leaves the real object in place
  3. Without destroy = false, the real object is destroyed too
  4. It needs a to argument naming the new address
  5. Its provisioners must use when = create
Show answer

Answer: A. from is required and holds the address to remove, B. lifecycle with destroy = false leaves the real object in place, C. Without destroy = false, the real object is destroyed too

from is required, destroy = false is how you hand off management, and by default the object is destroyed. There is no to argument, and removed-block provisioners must use when = destroy.

True or false

terraform state rm destroys the real infrastructure object it removes from state.

Show answer

Answer: False

False. It forgets the object only; it keeps running unmanaged. If the config still declares it, the next plan will want to create another one.

Practice 8 questions on this topic in Bitzu

Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.

Download on the App StoreGet it on Google Play

More Terraform Associate 004 topics in this module