source 블록
source 블록
이 주제에서는 source 블록에 대한 참조 정보를 다뤄요.
출처: Packer 공식 문서
본문
설명 (Description)
source 블록은 재사용 가능한 빌더 구성 블록을 정의해요. 빌더는 사용자 지정 플러그인에서 흔히 사용돼요.
예시 (Example)
다음 예시는 이름이 foo인 happycloud라는 빌더 타입의 소스를 정의해요:
# sources.pkr.hcl
source "happycloud" "foo" {
// ...
}
source.happycloud.foo 최상위 source 블록은 하나뿐이지만, 여러 번 사용할 수 있어요.
build 블록에서 source 블록을 참조해서 빌더를 시작할 수 있어요:
build {
sources = [
# Here Packer will use a default ami_name when saving the image.
"source.happycloud.example",
"source.happycloud.foo",
]
}
빌드 수준의 source 블록은 특정 source 필드를 설정할 수 있게 해 줘요. 각 필드는 한 번만 정의해야 하며, 현재 값을 오버라이드하는 것은 허용되지 않아요.
build {
source "source.happycloud.example" {
# Here Packer will use the provided image_name instead of defaulting it.
# Note that fields cannot be overwritten, in other words, you cannot
# set the 'image_name' field in the top-level source block and here at the
# same time
image_name = "build_specific_field"
}
}
소스 변수 (Source Variables)
프로비저너와 포스트-프로세서에서 소스의 이름과 타입에 접근하려면 다음 문법을 사용해요:
<build-name>.<source-type>.<source-name>
다음 예시는 빌드에 사용된 소스 이름을 조회해요:
source "null" "first-example" {
communicator = "none"
}
build {
name = "roles"
source "null.first-example" {
name = "consul"
}
source "null.first-example" {
name = "nomad"
}
source "null.first-example" {
name = "vault"
}
sources = ["null.first-example"]
provisioner "shell-local" {
inline = ["echo ${source.name} and ${source.type}"]
}
}
이 예시는 다음 값을 돌려줘요:
roles.null.consul-consul과null을 돌려줘요.roles.null.nomad-nomad와null을 돌려줘요.roles.null.vault-vault와null을 돌려줘요.roles.null.first-example-first-example과null을 돌려줘요.
더 알아보기 (Learn more)
- Packer 빌더에 대한 정보는 builders 참조 개요를 참고하세요.
- 커뮤니티가 유지 관리하는 빌더에 대한 정보는 커뮤니티 빌더 참조를 참고하세요.
- 자신만의 빌더를 만드는 방법은 사용자 지정 빌더 만들기를 참고하세요.