World map

 

BM: Baca dalam Bahasa Melayu

World T2: Inputs & Outputs

Variables and types

You will learn: to leave blanks in a blueprint with variables, and to give each one a type.

Checked with OpenTofu 1.13 on 1 Nov 2026

The problem

Your blueprint says โ€œKedai Kancilโ€ in five places. Now the boss opens a second shop, Warung Ali. What is the clean fix?

Pick one answer.

Try it

var.shop is a blank in this blueprint. Type tofu apply. OpenTofu asks you to fill it in.

Blueprint (your .tf files)init done

  • local_file.signnot 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.

A variable: A blank on the blueprint, filled in when you build: var.shop. One blueprint, many shops. is a blank. Use it as var.shop.

Watch

Each variable has a type: What kind of value a variable takes: string (text), number, bool (true or false), list, set, map or object.: the kind of value that fits. Sort them.

Drag a card into a box. Or tap the card, then tap the box.

          Predict

          tables has type = number. Someone types -var tables=lots. What happens?

          Pick one answer.

          Try it

          This blueprint allows 1 to 10 tables. Ask for 20: tofu plan -var tables=20. Then plan again with 6.

          Blueprint (your .tf files)init done

          • terraform_data.doornot 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.

          Error: Invalid value for variable. Plain words: the blueprintโ€™s own rule says 1 to 10.

          Check

          Good variable habit or not?

          Swipe right for good, left for needs work. Or use the buttons.

          1 / 4

          Give every variable a type

          Give every variable a type

          You did it!

          You can now leave blanks with variables and guard them with types.

          Go deeper (optional)

          More types: map(number) holds name-to-value pairs. set(string) is a list without repeats. object({ โ€ฆ }) groups named fields. A default makes a variable optional. sensitive = true hides a value on screen, but it is still in the state (World T3).

          Real mission

          1. tofu apply
          2. tofu apply -var shop=Warung
          3. tofu destroy

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