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?