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?