Terraform Best Practices
Terraform consultingTwitter @antonbabenkoTerraform Weekly
한국어 (Korean)
한국어 (Korean)
  • 어서오세요
  • 주요 개념
  • 코드 구조
  • 코드 구조 예제
    • Terragrunt
    • Terraform
      • Terraform을 사용한 소규모 인프라
      • Terraform을 사용한 중간 규모 인프라
      • Terraform을 사용한 대규모 인프라
  • 명명 규칙
  • 코드 스타일링
  • FAQ
  • 참고 자료
  • Terraform 구성(configurations) 작성하기
  • 워크샵
Powered by GitBook
On this page
  • locals를 사용해 리소스 간의 명시적 의존성 지정하기
  • Terraform 0.12 - 필수적 vs 선택적 인수
Export as PDF

Terraform 구성(configurations) 작성하기

Previous참고 자료Next워크샵

Last updated 1 year ago

locals를 사용해 리소스 간의 명시적 의존성 지정하기

Terraform 구성(configurations)에 직접적인 의존성이 없는 경우에도 특정 리소스가 삭제되어야 함을 Terraform에 알려주는 유용한 방법입니다.

Terraform 0.12 - 필수적 vs 선택적 인수

  1. var.website가 빈 맵이 아닌 경우 필수적 인수 index_document를 반드시 설정해야 합니다.

  2. 선택적 인수 error_document는 생략할 수 있습니다.

main.tf
variable "website" {
  type    = map(string)
  default = {}
}

resource "aws_s3_bucket" "this" {
  # omitted...

  dynamic "website" {
    for_each = length(keys(var.website)) == 0 ? [] : [var.website]

    content {
      index_document = website.value.index_document
      error_document = lookup(website.value, "error_document", null)
    }
  }
}
terraform.tfvars
website = {
  index_document = "index.html"
}
https://raw.githubusercontent.com/antonbabenko/terraform-best-practices/master/snippets/locals.tf