ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
Module (ယခင် lesson) က code reuse အတွက်ဖြစ်ပြီး, Workspace ကတော့ state isolation အတွက်ပါ — config folder တစ်ခုတည်းနေရာမှာပဲ `terraform workspace new dev`, `terraform workspace new prod` ဆိုပြီး workspace ၂ ခု create လုပ်ရင်, state file ကို workspace အလိုက် (`terraform.tfstate.d/dev/`, `terraform.tfstate.d/prod/`) ခွဲသိမ်းပေးပါတယ် — dev workspace မှာ apply လုပ်တာက prod workspace ရဲ့ resource ကို လုံးဝ မထိခိုက်ပါ။ `terraform.workspace` ဆိုတဲ့ built-in variable ကို config ထဲမှာ ကိုယ်တိုင် reference လုပ်ပြီး, workspace အလိုက် value ပြောင်းလို့လည်း ရပါတယ်.
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
`terraform workspace new staging` → `terraform workspace select staging` → `terraform apply` ဆိုတဲ့ sequence နဲ့ staging environment ကို default environment နဲ့ ခွဲထားပြီး run လို့ရပါတယ် — `instance_type = terraform.workspace == "prod" ? "t3.large" : "t3.micro"` ဆိုတဲ့ expression နဲ့ workspace အလိုက် value ကွဲပြားစွာ ချထားလို့လည်း ရပါတယ်.
အတူတူ ကြည့်မယ်
# Create and switch to a new workspace
terraform workspace new staging
# List all workspaces
terraform workspace list
# Switch back to default
terraform workspace select default
# See which workspace is currently active
terraform workspace show$ terraform workspace list
default
* staging
production၅ မိနစ် စမ်းကြည့်
`terraform workspace new dev` နဲ့ workspace အသစ်တစ်ခု create လုပ်ပြီး, `local_file` resource (Basic chapter) ကို apply ကြည့်ပါ — `default` workspace ကို ပြန် select လုပ်ပြီး state ခွဲနေတာကို confirm လုပ်ကြည့်ပါ။
သတိလေးတစ်ချက်
Workspace တွေအားလုံးက backend config (state storage location) တစ်ခုတည်းကို share ပါတယ် — access control ကို workspace level မှာ ခွဲမရပါ (production workspace ကို developer အားလုံး access ရနေနိုင်ပါတယ်)။