World map

 

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.

Blueprint: 1 resources. Built: 0.

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
Blueprint: 1 resources. Built: 3.

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
        Blueprint: 1 resources. Built: 3.

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

        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

        1. tofu init
        2. tofu apply
        3. tofu output
        4. tofu plan
        5. tofu destroy

        0 of 6 steps done ยท Your ticks are saved.