BM: Baca dalam Bahasa Melayu
World T4: Modules & Pipelines
Modules: a stall you can reuse
You will learn: how to write one stall design and build it many times, with a module.
Checked with OpenTofu 1.13 on 1 Nov 2026
The problem
Kedai Kancil has three kiosks. Each one was copied and pasted into main.tf. Now every sign needs new wording. How many places do you edit?
Pick one answer.
Watch
This is modules/kiosk/main.tf. Tap its input and its output.
0 of 2 found
A module: A stall design you can reuse: a folder of .tf files. Variables go in, outputs come out. is a stall design you can reuse: a folder of .tf files. Variables go in, outputs come out.
Predict
You copy a module block in main.tf and name it roti. Then you run tofu plan. What happens?
Pick one answer.
Try it
Add a third kiosk. In main.tf, copy a module block. Name it roti, with name = "roti-canai". Then plan, init and apply.
Blueprint (your .tf files)init done
module.teh.local_file.signmodule.nasi.local_file.sign
Built (the state file)state #1
module.nasi.local_file.signmodule.teh.local_file.sign
- teh_file
- teh-tarik.txt
Change a file, then run tofu plan to see what it means.
Hint
Only the block name andname change. source stays the same.Check
This is tofu state list now. Find the new kiosk in the register.
Tap the address that belongs to module roti.
0 of 1 found
Check
Where does each line live: in the module, or in the blueprint that calls it?
Drag a card into a box. Or tap the card, then tap the box.
You did it!
You can now wrap a design in a module and build it many times.
Go deeper (optional)
Modules can call other modules. Keep them small and boring: one clear job each. A module with one resource and ten inputs is usually just extra typing. tofu init sets up modules too. tofu get fetches modules only.
Real mission
tofu init && tofu applytofu state list
0 of 4 steps done ยท Your ticks are saved.
Bahasa Melayu
Kedai Kancil ada tiga kiosk. Setiap satu disalin dan ditampal dalam main.tf. Kini setiap papan tanda perlu ayat baharu. Berapa tempat anda perlu ubah?
Modul ialah reka bentuk gerai yang boleh diguna semula: satu folder fail .tf. Variable masuk, output keluar.
Anda salin satu blok module dalam main.tf dan namakannya roti. Kemudian anda jalankan tofu plan. Apa jadi?
Tambah kiosk ketiga. Dalam main.tf, salin satu blok module. Namakan roti, dengan name = "roti-canai". Kemudian plan, init dan apply.
name berubah. source kekal sama.Ini tofu state list sekarang. Cari kiosk baharu dalam daftar.
Di mana setiap baris duduk: dalam modul, atau dalam pelan yang memanggilnya?
Kini anda boleh bungkus reka bentuk dalam modul dan binanya banyak kali.
You finished this before. Practice is always welcome!
Official docs: OpenTofu: modules ยท OpenTofu: creating modules ยท Terraform: modules
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?