ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
Real-world project တစ်ခုမှာ network layer (VPC, subnet), compute layer (server), storage layer (database/bucket) ကို ခွဲပြီး module structure (`modules/network`, `modules/compute`, `modules/storage`) နဲ့ organize လေ့ရှိပါတယ် — layer တစ်ခုစီရဲ့ output ကို နောက် layer ရဲ့ input အဖြစ် ချိတ်ဆက်ပါတယ် (network module ရဲ့ subnet_id output ကို compute module ရဲ့ subnet_id input အဖြစ် ပေးသလိုမျိုးပါ)။ Root config ထဲမှာ module ၃ ခုကို order အလိုက် ခေါ်သုံးရင် dependency ကို Terraform ကိုယ်တိုင် graph ဖြင့် handle ပေးပါတယ်.
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
`modules/network/` (VPC + subnet), `modules/compute/` (server, subnet_id ကို input အနေနဲ့ လက်ခံ), `modules/storage/` (database) ဆိုပြီး module ၃ ခု ခွဲရေးပါ — root `main.tf` ထဲမှာ `module "network" { ... }` → `module "compute" { subnet_id = module.network.subnet_id }` → `module "storage" { ... }` ဆိုပြီး ချိတ်ဆက်ခေါ်သုံးပါ။ `terraform plan` run ရင် layer အားလုံးရဲ့ resource ကို တစ်ပြိုင်နက် preview ကြည့်နိုင်ပါတယ်.
အတူတူ ကြည့်မယ်
# root main.tf
module "network" {
source = "./modules/network"
}
module "compute" {
source = "./modules/compute"
subnet_id = module.network.subnet_id
}
module "storage" {
source = "./modules/storage"
}
output "web_server_ip" {
value = module.compute.public_ip
}$ terraform apply
module.network.aws_vpc.main: Creating...
module.network.aws_subnet.app: Creating...
module.compute.aws_instance.web: Creating...
module.storage.aws_db_instance.main: Creating...
Apply complete! Resources: 4 added, 0 changed, 0 destroyed.၅ မိနစ် စမ်းကြည့်
module 3 ခု (network/compute/storage) ကို ကိုယ်တိုင် folder ခွဲဖန်တီးပြီး, root config ကနေ ချိတ်ဆက်ခေါ်သုံးကြည့်ပါ — `terraform plan` run ပြီး layer အားလုံး ကိုက်ညီစွာ ချိတ်ဆက်ထားလားဆိုတာ verify လုပ်ကြည့်ပါ။
သတိလေးတစ်ချက်
Production project မှာ credential/cost ရှိတဲ့ provider (AWS) ကို အမှန်တကယ် apply လုပ်ခင် `terraform plan` ကို သေချာဖတ်ပါ — free tier limit ကျော်သွားရင် cost ဖြစ်ပေါ်နိုင်ပါတယ်။