BM: Baca dalam Bahasa Melayu
World T2: Inputs & Outputs ยท Boss challenge
Three stalls from one list
You will learn: to build many stalls from one list with variables, for_each and outputs.
Checked with OpenTofu 1.13 on 1 Nov 2026
The problem
Boss: Kedai Kancil opens a food court with three stalls: nasi, mee and roti. The blueprint lists only nasi. What is the quickest safe change?
Pick one answer.
Try it
In terraform.tfvars, add mee = 4 and roti = 2 to the map. Then tofu apply, and yes.
Blueprint (your .tf files)init done
local_file.stall[*]not built yet
Built (the state file)
Nothing built yet.
Change a file, then run tofu plan to see what it means.
stalls = {
nasi = 5
mee = 4
roti = 2
}Predict
stall_files joins every file name with a for expression. What does tofu output print?
Pick one answer.
Try it
The boss wants the stall names too. In outputs.tf, add the output below. Then apply.
Blueprint (your .tf files)init done
local_file.stall[*]not built yet
Built (the state file)state #1
local_file.stall["mee"]local_file.stall["nasi"]local_file.stall["roti"]
- stall_files
- stalls/mee.txt, stalls/nasi.txt, stalls/roti.txt
Change a file, then run tofu plan to see what it means.
output "stall_names" {
value = join(", ", keys(var.stalls))
}Check
Which tool did each job today?
Drag a card into a box. Or tap the card, then tap the box.
Try it
Mee closes. Remove its line from terraform.tfvars. Then type tofu plan. Only mee should go.
Blueprint (your .tf files)init done
local_file.stall[*]not built yet
Built (the state file)state #1
local_file.stall["mee"]local_file.stall["nasi"]local_file.stall["roti"]
- stall_files
- stalls/mee.txt, stalls/nasi.txt, stalls/roti.txt
Change a file, then run tofu plan to see what it means.
Hint
Delete one line, thentofu plan.You did it!
You can now build many stalls from one list, and share what you built.
Go deeper (optional)
Real rep (optional): build the food court on your own machine, then tidy up.
Real mission
tofu inittofu applytofu outputtofu plantofu destroy
0 of 6 steps done ยท Your ticks are saved.
Bahasa Melayu
Boss: Kedai Kancil buka medan selera dengan tiga gerai: nasi, mee dan roti. Pelan cuma senaraikan nasi. Apa perubahan paling cepat dan selamat?
Dalam terraform.tfvars, tambah mee = 4 dan roti = 2 ke dalam map. Kemudian tofu apply, dan yes.
stalls = {
nasi = 5
mee = 4
roti = 2
}
stall_files gabungkan setiap nama fail dengan ungkapan for. Apa tofu output paparkan?
Bos mahu nama gerai juga. Dalam outputs.tf, tambah output di bawah. Kemudian apply.
output "stall_names" {
value = join(", ", keys(var.stalls))
}
Alat mana buat setiap kerja hari ini?
Gerai mee tutup. Buang barisnya dari terraform.tfvars. Kemudian taip tofu plan. Hanya mee patut pergi.
tofu plan.Kini anda boleh bina banyak gerai dari satu senarai, dan kongsi apa yang dibina.
You finished this before. Practice is always welcome!
Official docs: OpenTofu: input variables ยท OpenTofu: the for_each meta-argument ยท OpenTofu: output values ยท OpenTofu: built-in functions
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?