World map

 

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.

Blueprint: 0 resources. Built: 0.

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.

      Blueprint: 0 resources. Built: 0.

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

      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.

      Blueprint: 0 resources. Built: 0.

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

      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

      1. tofu console
      2. upper("kedai kancil")
      3. join(", ", ["nasi", "mee"])
      4. exit

      0 of 4 steps done · Your ticks are saved.