📘 Terraform Series — Part 5
Post 4 မှာတော့ Variables, Outputs နဲ့ State ကို နားလည်ခဲ့ပါပြီ။
ဒါပေမယ့် —
👉 Code ကို reuse မလုပ်နိုင်သေးဘူး 👉 Team နဲ့ share မလုပ်နိုင်သေးဘူး
ဒီ post မှာ production-level ကို ဆက် သွားပါမယ်။
🎯 ဒီ post မှာ သင်လေ့လာမယ့်အရာ
- Modules ဆိုတာ ဘာလဲ
- Reusable Terraform code ရေးနည်း
- Remote state ဘာကြောင့်လိုအပ်လဲ
- S3 + DynamoDB အသုံးပြုပုံ
👉 In short: You will move to production-ready Terraform.
🔁 Modules — Reusable Code
Modules ဆိုတာ —
👉 Reusable Terraform component တစ်ခုပါ။
Example structure —
modules/
ec2/
main.tf
variables.tf
outputs.tf
🔹 Module အသုံးပြုခြင်း
Root main.tf ထဲမှာ —
module "ec2" {
source = "../../modules/ec2"
instance_type = "t2.micro"
}
👉 Code ထပ်မရေးဘဲ reuse လုပ်နိုင်ပါတယ်။
👉 In short: Modules reduce duplication.
🧠 Terraform State ပြဿနာ
လက်ရှိ state က —
terraform.tfstate
👉 Local မှာပဲ သိမ်းထားပါတယ် ❌
❌ ပြဿနာများ
- Team share မလုပ်နိုင်ဘူး
- Safe မဖြစ်ဘူး
- Conflict ဖြစ်နိုင်တယ်
🔹 Remote Backend ဖြေရှင်းချက်
State ကို —
👉 S3 ထဲသို့ ပြောင်းပါမယ် 👉 DynamoDB နဲ့ lock လုပ်ပါမယ်
🔹 Backend Configuration
terraform {
backend "s3" {
bucket = "my-terraform-state-bucket"
key = "dev/terraform.tfstate"
region = "ap-southeast-1"
dynamodb_table = "terraform-lock"
}
}
🔹 Initialize
terraform init
👉 State ကို S3 သို့ migrate လုပ်ပါလိမ့်မယ်။
🔒 DynamoDB ဘာကြောင့်လိုအပ်တာလဲ?
👉 State locking အတွက် အသုံးပြုပါတယ်။
ဒါက —
- Concurrent apply ကို တားဆီးပေးတယ်
- State corruption ကို ကာကွယ်ပေးတယ်
👉 In short: Prevents multiple users from breaking state.
🎯 ဒီနေ့ သင် လေ့လာခဲ့တာ
- Modules အသုံးပြုနည်း
- Remote backend setup
- Production Terraform concept
💡 DevOps Insight
Local state → learning only Remote state → real-world
🚀 နောက်ထပ် ဘာလာမှာလဲ?
နောက် post မှာ —
👉 Dev / Prod structure 👉 Professional repo design
👉 Terraform ကို enterprise level ထိ ယူသွားမယ် 🔥
📚 Terraform Learning Series
- Part 1 → Why Terraform
- Part 2 → Setup
- Part 3 → EC2
- Part 4 → Variables & State
- Part 5 → Modules & Backend (ဒီ post)
- Part 6 → Production Structure (လာမယ်)
👉 Let’s continue 🚀
👨💻 English Version
“Read full English version on Dev.to → visit Here

