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.
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.
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.
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
tofu applytofu apply -var shop=Warungtofu destroy
0 of 5 steps done ยท Your ticks are saved.
Bahasa Melayu
Pelan anda tulis โKedai Kancilโ di lima tempat. Kini bos buka kedai kedua, Warung Ali. Apa cara yang kemas?
var.shop ialah ruang kosong dalam pelan ini. Taip tofu apply. OpenTofu minta anda isi.
Variable (pemboleh ubah) ialah ruang kosong. Guna sebagai var.shop.
Setiap variable ada type (jenis): jenis nilai yang muat. Asingkan.
tables ada type = number. Seseorang taip -var tables=lots. Apa jadi?
Pelan ini benarkan 1 hingga 10 meja. Minta 20: tofu plan -var tables=20. Kemudian plan lagi dengan 6.
Error: Invalid value for variable. Maksudnya: peraturan pelan itu sendiri kata 1 hingga 10.
Tabiat variable yang baik atau tidak?
Kini anda boleh tinggalkan ruang kosong dengan variable dan kawalnya dengan jenis.
You finished this before. Practice is always welcome!
Official docs: OpenTofu: input variables ยท OpenTofu: types and values
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?