For the complete documentation index, see llms.txt. This page is also available as Markdown.

Terraform 구성(configurations) 작성하기

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

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

https://raw.githubusercontent.com/antonbabenko/terraform-best-practices/master/snippets/locals.tf

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)
    }
  }
}

Last updated