๐Ÿ“‚ IaC/Terraform

[Terraform] Output ์ถœ๋ ฅ ๋ณ€์ˆ˜

dhyuck 2022. 9. 3. 22:03
๋ฐ˜์‘ํ˜•

์ถœ๋ ฅ ๋ณ€์ˆ˜

  • ์ถœ๋ ฅ ๋ณ€์ˆ˜(output values)๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ฆฌ์†Œ์Šค์— ๋Œ€ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ๋‚ด๋ณด๋‚ผ ์ˆ˜ ์žˆ์œผ๋ฉฐ child module(์ž์‹ ๋ชจ๋“ˆ)์—์„œ root module(๋ฃจํŠธ ๋ชจ๋“ˆ)๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๊ณต์œ ํ• ๋•Œ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
  • ๋‚ด๋ณด๋‚ธ ๋ฐ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋‹ค๋ฅธ ์ธํ”„๋ผ์˜ ๊ตฌ์„ฑ์— ํ™œ์šฉํ•˜๊ฑฐ๋‚˜ ๋ฐ์ดํ„ฐ ์†Œ์Šค๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • output ์„ ์–ธ์€ ๋ชจ๋“  ๊ตฌ์„ฑํŒŒ์ผ์˜ ๋ชจ๋“  ์œ„์น˜์—์„œ ๊ฐ€๋Šฅํ•˜์ง€๋งŒ, outputs.tf์— ์„ ์–ธ ํ•  ๊ฒƒ์„ ๊ถŒ์žฅํ•ฉ๋‹ˆ๋‹ค.
  • output values๋Š” ๋ฃจํŠธ ๋ชจ๋“ˆ์˜ ์ƒํƒœ ํŒŒ์ผ์— ์ €์žฅ๋ฉ๋‹ˆ๋‹ค.
  • terraform output๋Š” output์— queryํ•˜๋Š” ๋ช…๋ น์ž…๋‹ˆ๋‹ค.

์ถœ๋ ฅ ๋ณ€์ˆ˜ ์„ ์–ธ

  • Output Blocks

    • description์€ ์„ ํƒ์‚ฌํ•ญ์ด์ง€๋งŒ ์ž‘์„ฑํ•  ๊ฒƒ์„ ๊ถŒ์žฅํ•ฉ๋‹ˆ๋‹ค.

    • terraform์˜ ํ‘œํ˜„์‹์˜ ๊ฒฐ๊ณผ๋ฅผ value๋กœ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

      output "vpc_id" {
      description = "ID of project VPC"
      value       = module.vpc.vpc_id
      }
      
      output "lb_url" {
      description = "URL of load balancer"
      value       = "http://${module.elb_http.this_elb_dns_name}/"
      }
      
      output "db_password" {
      description = "Database administrator password"
      value       = aws_db_instance.database.password
      sensitive   = true
      }

sensitive

  • output์ด password์™€ ๊ฐ™์€ ๋ฏผ๊ฐํ•œ ๊ฐ’์„ ๊ฐ€๋ฆฌํ‚ฌ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

  • sensitive๋ฅผ plan, apply, destory ๋‹จ๊ณ„์—์„œ console ์ถœ๋ ฅ์ด <sensitive>๋กœ ๋ณ€๊ฒฝ๋ฉ๋‹ˆ๋‹ค.

    ํ•˜์ง€๋งŒ output์œผ๋กœ ์ถœ๋ ฅํ•˜๋Š” ๊ฒฝ์šฐ, JSON ํ˜•์‹์œผ๋กœ ์ถœ๋ ฅํ•˜๋Š” ๊ฒฝ์šฐ, ๋ฃจํŠธ ๋ชจ๋“ˆ์—์„œ ์ž์‹๋ชจ๋“ˆ์˜ ์ถœ๋ ฅ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ๋“ฑ์—์„œ๋Š” sensitive๋กœ ๊ฐ€๋ ค์ง€์ง€ ์•Š์Šต๋‹ˆ๋‹ค.


๋ฐ˜์‘ํ˜•