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

Outputs

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

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

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

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

Resource တစ်ခု create ပြီးတဲ့နောက် Terraform/cloud provider ကနေ auto-generate ဖြစ်လာတဲ့ value (ဥပမာ - server ရဲ့ public IP address, database ရဲ့ connection endpoint) ရှိပါတယ် — apply run ပြီးရင် ဒီ value ကို terminal မှာ ချက်ချင်း မြင်ချင်ရင် Output block (`output "name" { value = ... }`) ကို သုံးပါတယ်။ Output ကို module (နောက် lesson) အချင်းချင်း data ကူးပို့ဖို့ (child module ရဲ့ output ကို parent module က input အဖြစ် သုံးခြင်း) အတွက်ပါ အသုံးများပါတယ်.

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

`output "server_ip" { value = aws_instance.web.public_ip }` လို့ define လုပ်ထားရင်, `terraform apply` ပြီးတဲ့အခါ terminal ထဲမှာ `server_ip = "54.123.45.67"` ဆိုတဲ့ output ကို ချက်ချင်း မြင်ရပါလိမ့်မယ် — SSH ချိတ်ဖို့ IP address ကို manual cloud console ကနေ ရှာစရာ မလိုတော့ပါ။ `terraform output` command ကို run ရင် output value အားလုံးကို ပြန်ကြည့်လို့ရပါတယ် (apply ပြီးနောက် ဘယ်အချိန်မဆို).

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

hcl
resource "aws_instance" "web" {
  ami           = "ami-0abcdef1234567890"
  instance_type = "t3.micro"
}

output "server_ip" {
  description = "Public IP address of the web server"
  value       = aws_instance.web.public_ip
}

output "server_id" {
  value = aws_instance.web.id
}
You should see
$ terraform apply
...
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Outputs:

server_id = "i-0123456789abcdef0"
server_ip = "54.123.45.67"

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

Output block ၂ ခု (server_ip, server_id) ကို ထည့်ပြီး apply ကြည့်ပါ — `terraform output` command ကို သီးခြား run ပြီး value တွေ ပြန်ကြည့်ကြည့်ပါ။

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

Sensitive output ကို `sensitive = true` ဆိုတဲ့ argument ထည့်ထားပါ — Terraform က terminal output ထဲမှာ value ကို `(sensitive value)` လို့ hide ပေးပါလိမ့်မယ် (state file ထဲမှာတော့ ဆက်ပေါ်နေဆဲပါ)။

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

  • Output value ကို sensitive data (password) အနေနဲ့ ထားပြီး `sensitive = true` mark မလုပ်ခြင်း — terminal/log ထဲ plain text ပေါ်နေနိုင်ပါတယ်
  • Output ကို resource ရဲ့ attribute name မှားရေးမိခြင်း (Registry documentation ကို ကိုးကားစစ်ဆေးသင့်ပါတယ်)

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

Output block ၂ ခု (server_ip, server_id) ကို ထည့်ပြီး apply ကြည့်ပါ — `terraform output` command ကို သီးခြား run ပြီး value တွေ ပြန်ကြည့်ကြည့်ပါ။

You'll know it worked when: $ terraform apply ... Apply complete! Resources: 1 added, 0 changed, 0 destroyed. Outputs: server_id = "i-0123456789abcdef0" server_ip = "54.123.45.67"

Outputs | Thuta Learning