ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
Terraform config ထဲမှာ password ကို hardcode ရေးထားရင် git repository ထဲ commit ဖြစ်ရင် leak ဖြစ်ပါတယ် — Variable ကို `sensitive = true` mark ထားရင် Terraform က plan/apply output ထဲမှာ value ကို hide ပေးပါတယ် (state file ထဲမှာတော့ ဆက်ပေါ်နေဆဲမို့ state encryption/access control ကို ခွဲသီးသန့် စဉ်းစားရပါမယ်)။ Credential (AWS access key) ကိုတော့ config ထဲ တိုက်ရိုက်မရေးဘဲ environment variable (`AWS_ACCESS_KEY_ID`) ဒါမှမဟုတ် credential file (`~/.aws/credentials`) ကနေ provider က auto-detect ဖတ်ယူအောင် setup လုပ်ရပါတယ်။ Production မှာ Vault (HashiCorp Vault) ဒါမှမဟုတ် cloud secret manager (AWS Secrets Manager) ကနေ secret ကို dynamic ဆွဲယူတာလည်း ရှိပါတယ်.
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
Database password ကို `variable "db_password" { type = string; sensitive = true }` လို့ define လုပ်ပြီး, value ကို `.tfvars` file (git-ignored) ဒါမှမဟုတ် environment variable (`TF_VAR_db_password`) ကနေ ပေးပို့ပါတယ် — `terraform plan` output ထဲမှာ `db_password = (sensitive value)` လို့ hide ပြပေးပါလိမ့်မယ်။ AWS credential ကို config ထဲ တိုက်ရိုက်မရေးဘဲ, `aws configure` command (ဒါမှမဟုတ် CI/CD environment variable) ကနေ provider က auto-detect ဖတ်ယူပါလိမ့်မယ်.
အတူတူ ကြည့်မယ်
variable "db_password" {
description = "Database master password"
type = string
sensitive = true
}
resource "aws_db_instance" "main" {
# ... other config ...
password = var.db_password
}
# Set the value via environment variable, never in the .tf file:
# TF_VAR_db_password="..." terraform apply$ terraform plan
~ resource "aws_db_instance" "main" {
~ password = (sensitive value)
}၅ မိနစ် စမ်းကြည့်
`sensitive = true` variable တစ်ခု define လုပ်ပြီး, `TF_VAR_<name>` environment variable နည်းလမ်းနဲ့ value ပေးပို့ကာ plan output ထဲမှာ value hide ဖြစ်နေတာ confirm လုပ်ကြည့်ပါ။
သတိလေးတစ်ချက်
State file (local ဖြစ်စေ remote ဖြစ်စေ) ထဲမှာ sensitive data အားလုံး plain text အနေနဲ့ ပါဝင်ပါတယ် — state file access ကို ကန့်သတ်ခြင်း (encryption at rest, IAM permission) ကို production မှာ မဖြစ်မနေ setup လုပ်ပါ။