ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
Local state (default) က laptop တစ်လုံးတည်းမှာပဲ ရှိပါတယ် — team member တခြားက state ကို မမြင်နိုင်ပါဘူး, ၂ ယောက်တစ်ပြိုင်နက် apply လုပ်ရင် state file ကွဲသွားနိုင်ပါတယ်။ Remote Backend (`backend "s3" { ... }`) က state file ကို shared location (S3 bucket, Terraform Cloud) မှာ သိမ်းပေးပြီး, team member အားလုံးက state အသစ်ဆုံးကို အမြဲ မြင်နိုင်ပါတယ်။ State Locking (DynamoDB table ကို S3 backend နဲ့ တွဲသုံးလေ့ရှိ) က တစ်ယောက် apply လုပ်နေချိန် နောက်တစ်ယောက် တစ်ပြိုင်နက် apply မလုပ်နိုင်အောင် lock ချထားပေးပါတယ် — state corruption ကို ကာကွယ်ပါတယ်.
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
`terraform { backend "s3" { bucket = "my-terraform-state"; key = "prod/terraform.tfstate"; region = "us-east-1"; dynamodb_table = "terraform-locks" } }` လို့ configure လုပ်ရင်, `terraform init` run တဲ့အခါ state ကို local ကနေ S3 ဆီ migrate လုပ်ပေးပါတယ် — အဲဒီနောက်ပိုင်း team member ဘယ်သူမဆို same config folder ကနေ `terraform apply` run ရင် state အသစ်ဆုံးကို အမြဲ ရရှိပါလိမ့်မယ်.
အတူတူ ကြည့်မယ်
terraform {
backend "s3" {
bucket = "my-terraform-state"
key = "prod/terraform.tfstate"
region = "us-east-1"
dynamodb_table = "terraform-locks"
encrypt = true
}
}$ terraform init
Initializing the backend...
Successfully configured the backend "s3"! Terraform will
automatically use this backend unless the backend configuration
changes.၅ မိနစ် စမ်းကြည့်
Remote backend config (S3 ဒါမှမဟုတ် သင်ရင်းနှီးတဲ့ provider) ကို ရေးကြည့်ပြီး, backend ကို configure လုပ်တဲ့အခါ Terraform ရဲ့ prompt/output ကို ကိုယ်တိုင် လေ့လာကြည့်ပါ (တကယ်တမ်း cloud resource create မလုပ်ပါနှင့်, dry-run/documentation review ပဲ လုပ်ပါ)။
သတိလေးတစ်ချက်
S3 bucket (state storage) ကို public access ပြုလုပ်မိရင် sensitive data အားလုံး (password, secret) leak ဖြစ်နိုင်ပါတယ် — bucket ကို private ထားပြီး encryption enable လုပ်ထားပါ။