BM: Baca dalam Bahasa Melayu
World T2: Inputs & Outputs
Locals: names for repeats
You will learn: to name a repeated value once with locals, and change it in one place.
Checked with OpenTofu 1.13 on 1 Nov 2026
The problem
The opening hours appear twice in the blueprint. Now the shop opens at 7am. What could go wrong?
content = "Open 8am to 10pm\n"
content = "Kedai Kancil, 8am to 10pm\n"Pick one answer.
Watch
Here the hours are written once, in a locals block. Tap every line that uses them.
Tap the lines that match.
0 of 2 found
A local value: A name for a value you reuse inside one blueprint: local.hours. Change it once; every use follows. gives a value one name, used anywhere in the blueprint.
Predict
You change hours once. How many files will the plan replace?
Pick one answer.
Try it
The shop opens at 7am now. Change hours once, to 7am to 11pm. Then tofu apply, and yes.
Blueprint (your .tf files)init done
local_file.boardlocal_file.door
Built (the state file)state #1
local_file.boardlocal_file.door
Change a file, then run tofu plan to see what it means.
Hint
Edit only thelocals block, then apply.Check
Variable or local?
Drag a card into a box. Or tap the card, then tap the box.
You did it!
You can now name a repeated value once with locals.
Go deeper (optional)
The block is locals (plural); you read one value as local.hours (singular). A local can use variables, functions and other locals, like upper(var.shop). Donβt overdo it: a local used only once just adds a hop to follow.
Bahasa Melayu
Waktu buka muncul dua kali dalam pelan. Kini kedai buka pukul 7 pagi. Apa yang boleh jadi masalah?
content = "Open 8am to 10pm\n"
content = "Kedai Kancil, 8am to 10pm\n"
Di sini waktu buka ditulis sekali, dalam blok locals. Tekan setiap baris yang menggunakannya.
Local value (nilai tempatan) beri satu nama kepada nilai, boleh diguna di mana-mana dalam pelan.
Anda tukar hours sekali. Berapa fail plan akan ganti?
Kedai kini buka pukul 7 pagi. Tukar hours sekali, jadi 7am to 11pm. Kemudian tofu apply, dan yes.
locals sahaja, kemudian apply.Variable atau local?
Kini anda boleh namakan nilai yang berulang sekali sahaja dengan locals.
You finished this before. Practice is always welcome!
Official docs: OpenTofu: local values
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?