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

Terraform Architecture

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

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

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

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

Configuration (`.tf` file တွေ) က 'ငါလိုချင်တဲ့ infrastructure ဘယ်လိုပုံစံ ဖြစ်စေချင်တယ်' ဆိုတဲ့ desired state ကို HCL နဲ့ ရေးထားတာပါ။ State (`terraform.tfstate` file) က Terraform ကိုယ်တိုင် 'ငါ ဘာတွေ create ပြီးသွားပြီလဲ' ဆိုတာကို မှတ်ထားတဲ့ database ပါ — Terraform run တိုင်း state ကို configuration နဲ့ နှိုင်းယှဉ်ပြီး ဘာပြောင်းရမလဲ ဆုံးဖြတ်ပါတယ်။ Provider (`aws`, `azurerm`, `google`, `kubernetes` စသည်) က Terraform ရဲ့ configuration ကို actual API call (AWS API, Azure API) အဖြစ် ပြောင်းပေးတဲ့ plugin ပါ — provider မရှိရင် Terraform က ဘယ် service ကိုမှ ချိတ်ဆက်လို့ မရပါဘူး။

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

Configuration ထဲမှာ 'AWS EC2 server တစ်လုံး လိုချင်တယ်' လို့ ရေးထားရင် — Terraform က state file ကို ဖွင့်ကြည့်ပါတယ် (server ရှိပြီးလား), မရှိသေးရင် AWS provider ကနေတစ်ဆင့် AWS API ကို 'server အသစ်ဖန်တီးပါ' ဆိုတဲ့ request ပို့ပါတယ်, ပြီးရင် state file ထဲ 'ဒီ server ဖန်တီးပြီးပြီ' လို့ မှတ်ထားပါတယ် — နောက်တစ်ခါ `terraform apply` ထပ်run ရင် state ထဲမှာ ရှိပြီးသားမို့ ထပ်ဖန်တီးမပေးတော့ပါ (idempotent)။

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

text
Terraform Core Concepts
=========================

.tf files (Configuration)
  "I want 1 server, 1 database" — desired state, written in HCL

terraform.tfstate (State)
  "Here's what actually exists right now" — Terraform's own record

Provider (e.g. aws, azurerm, google)
  Translates configuration into real API calls to the cloud

apply = compare Configuration vs State -> make API calls to close the gap
You should see
Configuration/State/Provider ၃ ခုရဲ့ ဆက်စပ်ပုံကို ရှင်းပြနိုင်မည်။

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

State file ဆိုတာ ဘာကြောင့် အရေးကြီးလဲ (state file ပျောက်သွားရင် ဘာဖြစ်နိုင်လဲ) စဉ်းစားပြီး ၂ ကြောင်း ရေးကြည့်ပါ။

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

State file ထဲမှာ resource ID, ဒါတင်မကဘဲ password/secret တွေပါ plain text အနေနဲ့ ပါဝင်နိုင်ပါတယ် — state file ကို git repository ထဲ commit မလုပ်ပါနှင့် (နောက် chapter မှာ remote state ကို လေ့လာပါမယ်)။

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

  • State file ကို 'ဖျက်လို့ရတဲ့ temp file' လို့ ထင်ခြင်း — state ပျောက်ရင် Terraform က ကိုယ့် infrastructure ဘာတွေ ရှိနေပြီလဲ လုံးဝ မသိတော့ပါ
  • Provider ကို install/configure မလုပ်ဘဲ configuration ရေးလို့ရမယ်ထင်ခြင်း

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

State file ဆိုတာ ဘာကြောင့် အရေးကြီးလဲ (state file ပျောက်သွားရင် ဘာဖြစ်နိုင်လဲ) စဉ်းစားပြီး ၂ ကြောင်း ရေးကြည့်ပါ။

You'll know it worked when: Configuration/State/Provider ၃ ခုရဲ့ ဆက်စပ်ပုံကို ရှင်းပြနိုင်မည်။

Terraform Architecture | Thuta Learning