output
root module
output "test" {
value = "smiley"
}
terraform apply --auto-approve

output이 잘 나온다.
child module에서 output
instance 을 쓴다고 가정하면
vi module/instance/main.tf
output "child-test" {
value = "child-smiley"
}
root module에서는
module "test"{
source "./base/instance"
}
output "child-name"{
value = module.test.child-name
}
module.
하고 모듈 이름을 적고 .
을 찍고 output 이름을 적는다.
child module 에서 loop를 사용한경우
module "ns" {
for_each = {
ns1 = "${var.private_ip_prefix}.1.20"
ns2 = "${var.private_ip_prefix}.1.21"
}
source = "./base/instance"
}
이런식으로 로프가 돌면서 여러개의 vm을 만들면
output "test"{
value = module.ns["ns1"].child-name
}
이런식으로 사용해야한다.
todo
그런데 아웃풋을 왜 쓰지???
Last updated
Was this helpful?