ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
Resource ဆိုတာ Terraform က create/manage လုပ်ပေးမယ့် 'အရာဝတ္ထု' တစ်ခုချင်းစီကို ကိုယ်စားပြုတာပါ — server, database, file, DNS record — resource type အားလုံးက ဒီ concept အောက်ကနေ လာပါတယ်။ `resource "<type>" "<local_name>"` ဆိုတဲ့ syntax ကို သုံးပြီး, block ထဲမှာ argument (config detail) ရေးထည့်ပါတယ်။ Terraform က ဒီ resource ကို state file ထဲ 'ငါ ဖန်တီးပြီးသား' လို့ မှတ်ထားပြီး, နောက်တစ်ကြိမ် `apply` ထပ် run ရင် (change မရှိရင်) ဘာမှ ထပ်မလုပ်တော့ပါ.
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
`terraform apply` ပြီးရင် `hello.txt` ဆိုတဲ့ file တကယ် disk ပေါ်မှာ ပေါ်လာမှာပါ — content ကို ပြင်ပြီး `apply` ထပ်run ရင် Terraform က 'ပြောင်းလဲမှုရှိတယ်' သိပြီး file ကို update ပေးပါလိမ့်မယ်။ `terraform destroy` run ရင် Terraform-managed resource အားလုံးကို ဖျက်ပေးပါတယ် — practice ပြီးတိုင်း cleanup လုပ်ဖို့ ဒီ command က အရေးကြီးပါတယ်.
အတူတူ ကြည့်မယ်
terraform {
required_providers {
local = {
source = "hashicorp/local"
version = "~> 2.5"
}
}
}
resource "local_file" "greeting" {
filename = "${path.module}/hello.txt"
content = "Hello, Terraform!"
}$ terraform apply
local_file.greeting: Creating...
local_file.greeting: Creation complete after 0s
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.၅ မိနစ် စမ်းကြည့်
အထက်က code ကို file အနေနဲ့ save လုပ်ပြီး `terraform init && terraform apply` run ကြည့်ပါ — `hello.txt` ပေါ်လာတာ confirm လုပ်ပြီးရင် `terraform destroy` နဲ့ ရှင်းပါ။
သတိလေးတစ်ချက်
`terraform destroy` က resource ကို 'ပြန်ယူလို့မရအောင်' ဖျက်ပေးပါတယ် — production state ပေါ်မှာ destroy command ကို အလွန် သတိထားပြီးမှ run ပါ။