내장 블록 개요
내장 블록 개요 (Built-in blocks overview)
이 문서는 Packer 언어에 내장된 구성 블록들의 개요를 제공해요. 이 블록들을 사용해서 HCL2로 Packer 템플릿을 작성할 수 있어요.
출처: Packer 공식 문서
본문
Introduction (소개)
블록(block)은 구성을 담는 컨테이너예요. Packer 템플릿에서 다음 유형의 블록을 사용할 수 있어요.
build블록은 특정 이미지 아티팩트를 만들기 위해 사용되는 빌더, 프로비저너, 포스트-프로세서의 특정 조합에 대한 구성을 담아요.source블록은 빌더 플러그인에 대한 구성을 담아요. 정의된 소스는 "build" 블록에서 사용되고 추가로 구성될 수 있어요.provisioner블록은 프로비저너 플러그인에 대한 구성을 담아요. 이 블록들은 build 블록 안에 중첩돼요.post-processor와post-processors블록은 포스트-프로세서 플러그인과 포스트-프로세서 플러그인 시퀀스에 대한 구성을 담아요. 이것들도build블록 안에 중첩돼요.variable블록은 구성에서 기본값을 정하거나 런타임에 사용자가 설정할 수 있는 변수에 대한 구성을 담아요.locals블록은 HCL 함수나 데이터 소스를 사용해서 만들거나, variables 블록에서 만든 변수들로 조합할 수 있는 변수에 대한 구성을 담아요. 문서에는 각 블록 유형에 대한 정보가 들어 있어요.
packer 블록 같은 다른 블록은 Packer 코어에 실행할 수 있는 버전에 대한 정보를 제공해요. required_plugins 블록은 Packer 코어를 도와줘요.
블록은 여러 파일에 정의할 수 있고, packer build folder 는 folder 라는 디렉터리의 파일만 사용해서 빌드해요.
Packer는 사용자 정의 블록을 지원하지 않아서, 언어에 내장된 블록만 사용할 수 있어요. 문서에는 사용 가능한 모든 내장 HCL2 블록이 포함돼 있어요.
Configuration examples (구성 예시)
# variables.pkr.hcl
variable "foo" {
type = string
default = "the default value of the `foo` variable"
description = "description of the `foo` variable"
sensitive = false
# When a variable is sensitive all string-values from that variable will be
# obfuscated from Packer's output.
}
- Variable 블록 문서.
# locals.pkr.hcl
locals {
# locals can be bare values like:
wee = local.baz
# locals can also be set with other variables :
baz = "Foo is '${var.foo}' but not '${local.wee}'"
}
# Use the singular local block if you need to mark a local as sensitive
local "mylocal" {
expression = "${var.secret_api_key}"
sensitive = true
}
- Locals 블록 문서.
# sources.pkr.hcl
source "happycloud" "foo" {
// ...
}
- source 블록 문서.
# build.pkr.hcl
build {
# use the `name` field to name a build in the logs.
# For example this present config will display
# "buildname.amazon-ebs.example-1" and "buildname.amazon-ebs.example-2"
name = "buildname"
sources = [
# use the optional plural `sources` list to simply use a `source`
# without changing any field.
"source.amazon-ebs.example-1",
]
source "source.amazon-ebs.example-2" {
# Use the singular `source` block set specific fields.
# Note that fields cannot be overwritten, in other words, you cannot
# set the 'output' field from the top-level source block and here.
output = "different value"
name = "differentname"
}
provisioner "shell" {
scripts = fileset(".", "scripts/{install,secure}.sh")
}
post-processor "shell-local" {
inline = ["echo Hello World from ${source.type}.${source.name}"]
}
}
- build 블록 문서.
# datasource.pkr.hcl
data "amazon-ami" "basic-example" {
// ...
}
- data 블록 문서.
더 알아보기 (Learn more)
- 이 페이지는 Packer 공식 문서에서 가져왔어요.