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.
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.
Change a file, then run tofu plan to see what it means.
Hint
Copy the four lines from the last card.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.
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
tofu init && tofu plantofu applytofu state show random_string.door
0 of 4 steps done · Your ticks are saved.
Bahasa Melayu
Dulu, seseorang tetapkan kod pintu kedai kepada KANCIL dengan tangan. Sekarang anda tambah pintu itu dalam pelan dan jalankan apply. Apa jadi?
Semak. Taip tofu plan dan cari will be created.
Blok import berkata: “Benda ini sudah wujud. Ambil alih, jangan bina.” to ialah alamat dalam pelan anda. id tunjuk benda sebenar.
Tambah blok import di bawah resource pintu dalam main.tf. Jalankan tofu plan: cari 1 to import. Kemudian tofu apply.
Import sudah selesai. Blok itu masih dalam main.tf. Apa sekarang?
⚠️ Hati-hati: id yang salah boleh gantikan benda sebenar. Begitu juga pelan yang tak sepadan dengannya. Leret: import selamat, atau perlu dibaiki?
Ada juga arahan yang lebih lama. Ia tulis daftar serta-merta, tanpa plan untuk dibaca dahulu. Bina arahan itu.
Kini anda boleh ambil alih benda yang dibina dengan tangan, dengan plan yang boleh disemak.
You finished this before. Practice is always welcome!
Official docs: OpenTofu: import blocks · tofu import · Terraform: import blocks
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?