Thuta Learning
ရှာဖွေရန်
ProjectsDevOpsintermediate

Project — Web App Infrastructure

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Project — Web App Infrastructure ကို ကြောက်စရာမလိုအောင် နားလည်မယ်
  • ကိုယ်တိုင် terraform command/HCL code ကို run ကြည့်တတ်မယ်
  • Real project ထဲမှာ ဒီ concept ကို ချက်ချင်း အသုံးချတတ်မယ်

ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်

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 ကြည့်နိုင်ပါတယ်.

အတူတူ ကြည့်မယ်

hcl
# 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
}
You should see
$ 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 ဖြစ်ပေါ်နိုင်ပါတယ်။

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • Module input/output name ကို layer အချင်းချင်း မကိုက်အောင် ရေးမိခြင်း (network module ရဲ့ output name eq compute module ရဲ့ input name)
  • Layer အားလုံးကို module တစ်ခုတည်းထဲ ထည့်ရေးခြင်း — reusability/readability ကျဆင်းစေပါတယ်

အခု ကိုယ်တိုင် စမ်းကြည့်

module 3 ခု (network/compute/storage) ကို ကိုယ်တိုင် folder ခွဲဖန်တီးပြီး, root config ကနေ ချိတ်ဆက်ခေါ်သုံးကြည့်ပါ — `terraform plan` run ပြီး layer အားလုံး ကိုက်ညီစွာ ချိတ်ဆက်ထားလားဆိုတာ verify လုပ်ကြည့်ပါ။

You'll know it worked when: $ 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.

Project — Web App Infrastructure | Thuta Learning