World map

 

BM: Baca dalam Bahasa Melayu

World T3: State & Teams

import blocks

You will learn: how to adopt something that was built by hand, without building it again.

Checked with OpenTofu 1.13 on 1 Nov 2026

The problem

Long ago, someone set the shop’s door code to KANCIL by hand. Now you add the door to the blueprint and apply. What happens?

Pick one answer.

Try it

Check it. Type tofu plan and look for will be created.

Blueprint (your .tf files)init done

  • random_string.doornot built yet

Built (the state file)

Nothing built yet.

Blueprint: 1 resources. Built: 0.

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

Watch

Tap the line that names the real thing to adopt.

0 of 1 found

An import block: Code that adopts something already built by hand, so OpenTofu manages it without building it again. says: “This already exists. Adopt it, don’t build it.” to is the address in your blueprint. id points at the real thing.

Try it

Add the import block under the door resource in main.tf. Run tofu plan: look for 1 to import. Then tofu apply.

Blueprint (your .tf files)init done

  • random_string.doornot built yet

Built (the state file)

Nothing built yet.

Blueprint: 1 resources. Built: 0.

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

Predict

The import is done. The block is still in main.tf. What now?

Pick one answer.

Check

⚠️ Careful: a mistyped id can replace the real thing. So can a blueprint that doesn’t match it. Swipe: safe import, or needs work?

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

1 / 4

Read the plan first: "1 to import, 0 to destroy"

Read the plan first: "1 to import, 0 to destroy"

Watch

There is also an older command. It writes the register at once, with no plan to read first. Build it.

Tap the pieces in the right order.

…

You did it!

You can now adopt something built by hand, with a plan you can review.

Go deeper (optional)

An import block can use for_each to adopt many things at once. tofu plan -generate-config-out=generated.tf can draft the resource blocks for you; the docs still call it experimental. Each provider’s docs list its import id, in an “Import” section.

Real mission

  1. tofu init && tofu plan
  2. tofu apply
  3. tofu state show random_string.door

0 of 4 steps done · Your ticks are saved.