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 post-processors block allows to define lists of
post-processors, that will run
from the artifact of each build.
# builds.pkr.hclbuild{# ...post-processors{
post-processor "shell-local"{# create an artifice.txt file containing "hello"inline=["echo hello > artifice.txt"]}
post-processor "artifice"{# tell packer this is now the new artifactfiles=["artifice.txt"]}
post-processor "checksum"{# checksum artifice.txtchecksum_types=["md5", "sha512"]# checksum the artifactkeep_input_artifact=true# keep the artifact}}}
# builds.pkr.hclbuild{# ...post-processors{ post-processor "shell-local"{# create an artifice.txt file containing "hello"inline=["echo hello > artifice.txt"]} post-processor "artifice"{# tell packer this is now the new artifactfiles=["artifice.txt"]} post-processor "checksum"{# checksum artifice.txtchecksum_types=["md5", "sha512"]# checksum the artifactkeep_input_artifact=true# keep the artifact}}}
The post-processor block
allows to define multiple post-processors that will run from the Artifact of
each build. Read the post-processor documentation to know how to use a
post-processor.
»Difference between a post-processor and a post-processors block
These two templates are doing the same thing:
# builds.pkr.hclbuild{# ... build image
post-processor "checksum"{# checksum imagechecksum_types=["md5", "sha512"]# checksum the artifact}
post-processor "amazon-import"{# upload image to AWS}
post-processor "googlecompute-import"{# upload image to GCP}}
# builds.pkr.hclbuild{# ... build image post-processor "checksum"{# checksum imagechecksum_types=["md5", "sha512"]# checksum the artifact} post-processor "amazon-import"{# upload image to AWS} post-processor "googlecompute-import"{# upload image to GCP}}
# builds.pkr.hclbuild{# ... build imagepost-processors{
post-processor "checksum"{# checksum imagechecksum_types=["md5", "sha512"]# checksum the artifact}}post-processors{
post-processor "amazon-import"{# upload image to AWS}}post-processors{
post-processor "googlecompute-import"{# upload image to GCP}}}
# builds.pkr.hclbuild{# ... build imagepost-processors{ post-processor "checksum"{# checksum imagechecksum_types=["md5", "sha512"]# checksum the artifact}}post-processors{ post-processor "amazon-import"{# upload image to AWS}}post-processors{ post-processor "googlecompute-import"{# upload image to GCP}}}
Each of these post-processors will start after each build -- that is, after
each provision step has run on each source --. In all cases the source image is
going to be deleted.