Thuta Learning
ရှာဖွေရန်
AdvancedDevOpsintermediate

Testing & CI/CD Basics

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Testing & CI/CD Basics ကို ကြောက်စရာမလိုအောင် နားလည်မယ်
  • ကိုယ်တိုင် terraform command/HCL code ကို run ကြည့်တတ်မယ်
  • Real project ထဲမှာ ဒီ concept ကို ချက်ချင်း အသုံးချတတ်မယ်

ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်

`terraform validate` က syntax error (typo, wrong argument name) ကို cloud API ခေါ်စရာ မလိုဘဲ local မှာပဲ စစ်ပေးပါတယ် — commit မလုပ်ခင် quick sanity check အနေနဲ့ အသုံးဝင်ပါတယ်။ `terraform fmt` က code style (indentation, spacing) ကို standard format အတိုင်း auto-fix ပေးပါတယ် — team member အားလုံးက code style တူညီအောင် ကူညီပေးပါတယ်။ CI/CD pipeline (GitHub Actions) ထဲမှာ Pull Request တင်တိုင်း `terraform plan` ကို auto-run ပြီး comment အနေနဲ့ ပြပေးအောင် setup လုပ်လေ့ရှိပါတယ် — team member က code review လုပ်တဲ့အခါ 'ဘာတွေ ပြောင်းမလဲ' ကို PR ပေါ်မှာပဲ တွေ့နိုင်ပါတယ်, `apply` ကတော့ merge ပြီးမှ (ဒါမှမဟုတ် manual approval ရမှ) run ပါလေ့ရှိပါတယ်.

လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်

GitHub Actions workflow file ထဲမှာ `terraform fmt -check` (format မမှန်ရင် fail), `terraform validate` (syntax error ရှိရင် fail), `terraform plan` (change preview) ကို step အလိုက် run ထားရင် — developer က config ကို push လိုက်တိုင်း automatic check ဖြစ်သွားပြီး, human error ကို early ရှာတွေ့နိုင်ပါတယ်.

အတူတူ ကြည့်မယ်

yaml
# .github/workflows/terraform.yml (simplified)
name: Terraform
on: [pull_request]
jobs:
  plan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: hashicorp/setup-terraform@v3
      - run: terraform init
      - run: terraform fmt -check
      - run: terraform validate
      - run: terraform plan
You should see
$ terraform fmt -check
$ terraform validate
Success! The configuration is valid.

$ terraform plan
Plan: 2 to add, 0 to change, 0 to destroy.

၅ မိနစ် စမ်းကြည့်

Local config folder တစ်ခုမှာ `terraform fmt -check` နဲ့ `terraform validate` command နှစ်ခုလုံးကို run ကြည့်ပါ — code style တမင် ရှုပ်ထွေးအောင် ရေးထားပြီး `fmt` က ဘယ်လို auto-fix ပေးလဲ ကြည့်ကြည့်ပါ။

သတိလေးတစ်ချက်

CI/CD pipeline ရဲ့ credential (AWS access key) ကို repository secret အနေနဲ့ properly သိမ်းထားပါ — workflow file ထဲ hardcode လုံးဝ မရေးပါနှင့်။

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • `terraform apply` ကို CI/CD pipeline ထဲမှာ approval step မထားဘဲ auto-run ဖြစ်အောင် setup လုပ်ခြင်း — production resource ကို accidental apply ဖြစ်နိုင်ပါတယ်
  • `terraform validate` က provider credential/network error ကိုပါ catch လုပ်ပေးမယ်လို့ ထင်ခြင်း — validate က syntax/type check ပဲ လုပ်ပေးပါတယ်, real API error ကို plan/apply အချိန်မှသာ တွေ့ရပါလိမ့်မယ်

အခု ကိုယ်တိုင် စမ်းကြည့်

Local config folder တစ်ခုမှာ `terraform fmt -check` နဲ့ `terraform validate` command နှစ်ခုလုံးကို run ကြည့်ပါ — code style တမင် ရှုပ်ထွေးအောင် ရေးထားပြီး `fmt` က ဘယ်လို auto-fix ပေးလဲ ကြည့်ကြည့်ပါ။

You'll know it worked when: $ terraform fmt -check $ terraform validate Success! The configuration is valid. $ terraform plan Plan: 2 to add, 0 to change, 0 to destroy.

Testing & CI/CD Basics | Thuta Learning