»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 and post-processors blocks contain configuration for post-processor plugins and post-processor plugin sequences. They are also nested within build 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.

Use the sidebar to navigate to detailed documentation for each of these blocks.

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 navigation for this section includes a list of all of the available built-in HCL2 blocks.

»Config example:

  • Variable block documentation.
  • Locals block documentation.
  • source block documentation.
  • build block documentation.
  • data block documentation.