source 블록

source 블록 (source block)

이 문서는 build 블록 안에 중첩된 source 블록에 대한 참조 정보를 제공해요.

출처: Packer 공식 문서

본문

Description (설명)

구성(configuration)의 다른 곳에서 정의된 빌더를 재사용하려면 build 블록에 source 블록을 추가해요. Packer는 최상위 source 블록에서 아직 설정되지 않은 소스 필드를 채워 넣어요.

빌드 레벨의 source 블록은 자신의 내용을 해당 최상위 source 블록과 병합(merge)해서 구현돼요. 그리고 source 파라미터가 두 번 정의될 때 생기는 모호함(ambiguity)이 발생하면 packer build 커맨드는 실패해요.

예를 들어 아래 예시에서 최상위 lxd.arch source 블록이 output_image 필드도 정의했다거나, 빌드 레벨 source 블록 중 하나가 이미지 필드를 재정의했다면 Packer는 오류를 내요.

# file: builds.pkr.hcl
source "lxd" "arch" {
  image = "archlinux"
}

build {
  # Use the singular `source` block set specific fields.
  # Note that fields cannot be overwritten, in other words, you cannot
  # set the 'image' field from the top-level source block in here, as well as
  # the 'name' and 'output_image' fields cannot be set in the top-level source block.
  source "lxd.arch" {
    # Setting the name field allows to rename the source only for this build section.
    name = "nomad"
    output_image = "nomad"
  }

  provisioner "shell" {
    inline = [ "echo installing nomad" ]
  }
}

build {
  source "lxd.arch" {
    name = "consul"
    output_image = "consul"
  }

  provisioner "shell" {
    inline = [ "echo installing consul" ]
  }
}

더 알아보기 (Learn more)