output은 모듈/루트에서 바깥으로 보여줄 결과.
예: 인스턴스 IP, ALB DNS, 서브넷 ID 같은 “다음 단계에서 필요할 값”.
output "<이름>" { value = <표현식> }terraform output, terraform output -raw name, -jsonmodule.<모듈명>.<output명>sensitive = true로 콘솔 표시만 숨김(상태파일엔 저장됨)# outputs.tf
output "public_ip" {
description = "웹서버 퍼블릭 IP"
value = aws_instance.web.public_ip
}
터미널:
terraform apply
terraform output # 모든 출력
terraform output public_ip # 특정 출력
# modules/vpc/outputs.tf (자식)
output "public_subnet_ids" {
value = aws_subnet.public[*].id
}
# root/main.tf (부모)
module "vpc" {
source = "./modules/vpc"
}
resource "aws_instance" "web" {
subnet_id = module.vpc.public_subnet_ids[0]
}
output "alb" {
description = "ALB 식별자 묶음"
value = {
dns = aws_lb.app.dns_name
arn = aws_lb.app.arn
sg = aws_security_group.alb.id
}
}
variable "db_password" { type = string; sensitive = true }
output "db_password" {
value = var.db_password
sensitive = true # 콘솔에서만 숨김, state에는 저장됨
}
# 자동화에선:
# terraform output -raw db_password # 기계가 읽도록
sensitive = true + 상태 백엔드(암호화/IAM) 보안# outputs.tf (루트 또는 모듈)
output "ids" {
description = "필요 식별자 모음"
value = {
vpc_id = aws_vpc.main.id
public_subnet= aws_subnet.public.id
web_ip = aws_instance.web.public_ip
}
}
output "secrets" {
value = { db_password = var.db_password }
sensitive = true
}
한 줄 결론: output = 다음 사람이/다음 스택이 볼 값.
꼭 필요한 것만, 깔끔한 이름으로, 비밀은 가리고!