World map

 

BM: Baca dalam Bahasa Melayu

World T3: State & Teams

moved blocks and refactors

You will learn: how to rename things in the blueprint without tearing them down.

Checked with OpenTofu 1.13 on 1 Nov 2026

The problem

You renamed random_pet.stall to random_pet.chef in main.tf. Nothing else. Read the plan.

Tap what OpenTofu will do to each one.

+ create~ update in place- destroy-/+ replace

0 of 2 read

  1.   # random_pet.chef
      + resource "random_pet" "chef" {
          + id        = (known after apply)
          + length    = 2
          + separator = "-"
        }
    

    What happens to random_pet.chef?

  2.   # random_pet.stall
      - resource "random_pet" "stall" {
          - id        = "lucky-civet" -> null
          - length    = 2 -> null
          - separator = "-" -> null
        }
    

    What happens to random_pet.stall?

The summary line shows when you finish.

Watch

Tap the line with the old name.

0 of 1 found

OpenTofu knows things by their address. A new name looks like a new thing. A moved block: Code that says: same thing, new address. A rename then changes nothing real. says: “Same thing, new name.”

Try it

Add the moved block to main.tf. Then tofu plan: look for has moved to. Then tofu apply.

Blueprint (your .tf files)init done

  • local_file.menu
  • random_pet.chefnot built yet

Built (the state file)state #1

  • local_file.menu
  • random_pet.stall
stall
lucky-civet
Blueprint: 2 resources. Built: 2.

Change a file, then run tofu plan to see what it means.

Predict

Next refactor: count becomes for_each. So random_pet.stall[0] becomes random_pet.stall["nasi"]. What keeps it alive?

Pick one answer.

Check

Which changes need a moved block?

Drag a card into a box. Or tap the card, then tap the box.

      Watch

      The old way edits the register directly. Nobody reviews it. Build it anyway, so you can read it.

      Tap the pieces in the right order.

      …

      Check

      You review a teammate’s refactor. Swipe: good, or needs work?

      Swipe right for good, left for needs work. Or use the buttons.

      1 / 4

      Renamed a resource and added a moved block in the same change

      Renamed a resource and added a moved block in the same change

      You did it!

      You can now rename and reshuffle the blueprint without rebuilding anything.

      Go deeper (optional)

      moved also renames whole modules: from = module.a, to = module.b. To stop managing a thing without destroying it, use a removed block with lifecycle { destroy = false }. A module others use should keep its moved blocks for a long time.

      Real mission

      1. tofu init && tofu apply
      2. tofu plan
      3. tofu plan
      4. tofu apply

      0 of 4 steps done · Your ticks are saved.