ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
State file (`terraform.tfstate`) ထဲမှာ resource တစ်ခုချင်းစီရဲ့ current attribute အားလုံး (ID, IP address, tag) ကို JSON format နဲ့ မှတ်ထားပါတယ် — Terraform run တိုင်း configuration (ငါလိုချင်တာ) ကို state (ငါဘာရှိပြီးသားလဲ) နဲ့ diff ယူပြီး ဘာလုပ်ရမလဲ ဆုံးဖြတ်ပါတယ်။ State file ပျောက်သွားရင် Terraform က resource တွေ ရှိနေတယ်ဆိုတာတောင် 'မသိတော့' ပါဘူး — ထပ်ပြီး create ဖို့ ကြိုးစားနိုင်ပါတယ် (duplicate resource ဖြစ်နိုင်ပါတယ်)။ `terraform state list` (resource list ကြည့်ခြင်း), `terraform state show <resource>` (attribute detail ကြည့်ခြင်း) command တွေက state ကို inspect လုပ်ဖို့ အသုံးဝင်ပါတယ်.
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
Team ၂ ယောက် (local laptop ၂ လုံး) က state file ကို local disk မှာပဲ သိမ်းထားရင် — တစ်ယောက်က apply လုပ်ပြီးရင် နောက်တစ်ယောက်ရဲ့ state က stale (updated မဖြစ်) ဖြစ်နေနိုင်ပါတယ် — conflict/duplicate resource ဖြစ်နိုင်ပါတယ် (ဒါကြောင့် production မှာ Remote State (နောက် chapter) ကို သုံးရပါတယ်)။
အတူတူ ကြည့်မယ်
# List all resources Terraform is tracking
terraform state list
# Show full detail of one resource
terraform state show aws_instance.web
# See the raw state file (JSON) — read-only inspection
cat terraform.tfstate$ terraform state list
aws_instance.web
local_file.greeting၅ မိနစ် စမ်းကြည့်
First-resource lesson ရဲ့ local_file resource ကို apply ထားထားပြီးဆိုရင် `terraform state list` နဲ့ `terraform state show local_file.greeting` ကို run ကြည့်ပါ — state ထဲက attribute တွေကို ကိုယ်တိုင် ဖတ်ကြည့်ပါ။
သတိလေးတစ်ချက်
State file ကို backup မထားဘဲ ဖျက်မိရင် (ဒါမှမဟုတ် corrupt ဖြစ်ရင်) production infrastructure ကို ပြန်လည် manage ရခက်ခဲသွားနိုင်ပါတယ် — Remote State + versioning ကို production မှာ အမြဲသုံးပါ။