World map

 

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.board
  • local_file.door

Built (the state file)state #1

  • local_file.board
  • local_file.door
Blueprint: 2 resources. Built: 2.

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

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.