Built-in Blocks
Note: This page is about HCL2 Packer templates. HCL2 templates were first introduced as a beta feature into Packer version 1.5. As of v1.7, HCL2 support is no longer in beta, and is the preferred way to write Packer configuration. For the old-style stable configuration language see template docs. As of v1.6.2, you can convert your legacy JSON template into an HCL2 config file using the hcl2_upgrade command.
The Packer - HCL2 language includes a number of built-in blocks that you can use to configure builds. A block is a container for configuration.
The most important blocks can be broken into a couple of major types:
build
blocks contain configuration for a specific combination of builders, provisioners, and post-processors used to create a specific image artifact.source
blocks contain configuration for builder plugins. Once defined, sources can be used and further configured by the "build" block.provisioner
blocks contain configuration for provisioner plugins. These blocks are nested inside of a build block.post-processor
andpost-processors
blocks contain configuration for post-processor plugins and post-processor plugin sequences. They are also nested withinbuild
blocks.variable
blocks contain configuration for variables that can either be defaulted in configuration or set by the user at runtime.locals
blocks contain configuration for variables that can be created using HCL functions or data sources, or composited from variables created in the variables blocks.
The documentation contains information for each block type.
Other blocks, such as the "packer" block, provide information to the Packer core about what version it is allowed to run. The "required_plugins" block helps the Packer core
Blocks can be defined in multiple files and packer build folder
will build
using solely the files from a directory named folder
.
Packer does not support user-defined blocks and so only the blocks built in to the language are available for use. The documentation includes all of the available built-in HCL2 blocks.
Config example: