BM: Baca dalam Bahasa Melayu
World T2: Inputs & Outputs
Expressions and functions
You will learn: to shape values with functions, conditionals and for expressions.
Checked with OpenTofu 1.13 on 1 Nov 2026
The problem
The sign must shout KEDAI KANCIL in capitals. The variable says “Kedai Kancil”. Do you add a second variable in capitals?
Pick one answer.
Watch
This blueprint only has outputs. Type tofu plan and read Changes to Outputs.
Blueprint (your .tf files)init done
No resources in the files yet.
Built (the state file)
Nothing built yet.
Change a file, then run tofu plan to see what it means.
Each value is an expression: Anything that works out a value: "text", var.shop, 2 + 3, or a function call.: something OpenTofu works out.
Check
Each function: A built-in helper that turns values into new ones: upper("kancil") gives "KANCIL". shapes a value. Text or lists?
Drag a card into a box. Or tap the card, then tap the box.
Try it
Make the sign shout. In main.tf, change value = var.shop to value = upper(var.shop). Then tofu apply, yes.
Blueprint (your .tf files)init done
No resources in the files yet.
Built (the state file)
Nothing built yet.
Change a file, then run tofu plan to see what it means.
Hint
Wrapvar.shop in upper( ).Predict
A conditional: condition ? this : that. It picks one of two values, like var.open ? "OPEN" : "CLOSED". picks one of two values. With open = false, what does door say?
output "door" {
value = var.open ? "OPEN" : "CLOSED"
}Pick one answer.
Try it
Close the shop for the night: tofu apply -var open=false, then yes.
Blueprint (your .tf files)init done
No resources in the files yet.
Built (the state file)
Nothing built yet.
Change a file, then run tofu plan to see what it means.
Hint
tofu apply -var open=false, then yes.Check
A for expression changes every item. What does this give?
[for s in var.stalls : upper(s)]Pick one answer.
You did it!
You can now shape values with functions, conditionals and for.
Go deeper (optional)
Where the story breaks: a paper blueprint can’t fill its own blanks. Ours works things out, loops, and makes many stalls from one drawing.
tofu console lets you try expressions one at a time. It is not in this practice terminal; try it on your own computer.
Real mission
tofu consoleupper("kedai kancil")join(", ", ["nasi", "mee"])exit
0 of 4 steps done · Your ticks are saved.
Bahasa Melayu
Papan tanda mesti tulis KEDAI KANCIL dalam huruf besar. Variable tulis “Kedai Kancil”. Perlukah tambah variable kedua dalam huruf besar?
Pelan ini cuma ada output. Taip tofu plan dan baca Changes to Outputs.
Setiap value ialah expression (ungkapan): sesuatu yang OpenTofu kira.
Setiap function (fungsi) bentuk satu nilai. Teks atau senarai?
Buat papan tanda guna huruf besar. Dalam main.tf, tukar value = var.shop jadi value = upper(var.shop). Kemudian tofu apply, yes.
var.shop dengan upper( ).Conditional (bersyarat) pilih satu daripada dua nilai. Dengan open = false, apa door kata?
output "door" {
value = var.open ? "OPEN" : "CLOSED"
}
Tutup kedai untuk malam ini: tofu apply -var open=false, kemudian yes.
tofu apply -var open=false, kemudian yes.Ungkapan for ubah setiap item. Apa hasilnya?
[for s in var.stalls : upper(s)]
Kini anda boleh bentuk nilai dengan fungsi, conditional dan for.
You finished this before. Practice is always welcome!
Official docs: OpenTofu: expressions · OpenTofu: built-in functions · OpenTofu: conditional expressions · OpenTofu: for expressions
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?