Packer
source block
This topic providers reference information about the source
block.
Description
The source
block defines reusable builder configuration blocks. Builders are commonly used in custom plugins.
Example
The following example defines a source for a builder type called happycloud
with the name foo
:
# sources.pkr.hcl
source "happycloud" "foo" {
// ...
}
There is only one source.happycloud.foo
top-level source block, but it can be used more than once.
You can start builders by referring to source
blocks from a build
block :
build {
sources = [
# Here Packer will use a default ami_name when saving the image.
"source.happycloud.example",
"source.happycloud.foo",
]
}
The build-level source
block allows to set specific
source fields. Each field must be defined only once and it is currently not
allowed to override a value.
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
Use the following syntax to access the name
and type
of your source
from provisioners and post-processors:
<build-name>.<source-type>.<source-name>
The following example queries source names used in the build:
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}"]
}
}
The example returns the following values:
roles.null.consul
: Returnsconsul
andnull
roles.null.nomad
: Returnsnomad
andnull
roles.null.vault
: Returnsvault
andnull
roles.null.first-example
: Returnsfirst-example
andnull
Related
The list of available builders can be found in the builders section.
A list of community builders is available.
Create your own custom builder !