ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
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 ပြီးနောက် ဘယ်အချိန်မဆို).
အတူတူ ကြည့်မယ်
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
}$ 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 ထဲမှာတော့ ဆက်ပေါ်နေဆဲပါ)။