June 20-22 Announcing HashiConf Europe full schedule: keynotes, sessions, labs & more Register Now
  • Infrastructure
    • terraform
    • packer
  • Networking
    • consul
  • Security
    • vault
    • boundary
  • Applications
    • nomad
    • waypoint
    • vagrant
  • HashiCorp Cloud Platform

    A fully managed platform to automate infrastructure on any cloud with HashiCorp products.

    • consul
    • terraform
    • vault
    • packerbeta
    Visit cloud.hashicorp.com
  • Overview
  • Tutorials
  • Docs
  • Plugins
  • Community
GitHubInstall PackerTry HCP Packer
    • v1.8.x (latest)
    • v1.7.x
    • v1.6.x
    • v1.5.x

  • Terminology
    • Overview
    • init
      • Overview
      • install
      • installed
      • remove
      • required
    • build
    • console
    • fix
    • fmt
    • inspect
    • validate
    • hcl2_upgrade
    • Overview
      • Overview
        • Overview
          • Overview
          • hcp_packer_registry
          • source
          • provisioner
          • post-processor
          • post-processors
        • locals
        • source
        • variable
        • packer
        • data
        • Overview
          • aws_secretsmanager
          • consul
          • env
          • vault
          • abs
          • ceil
          • floor
          • log
          • max
          • min
          • parseint
          • pow
          • signum
          • chomp
          • format
          • formatlist
          • indent
          • join
          • lower
          • replace
          • regex_replace
          • regex
          • regexall
          • split
          • strrev
          • substr
          • title
          • trim
          • trimprefix
          • trimsuffix
          • trimspace
          • upper
          • chunklist
          • coalesce
          • coalescelist
          • compact
          • concat
          • contains
          • distinct
          • element
          • flatten
          • index
          • keys
          • length
          • lookup
          • merge
          • range
          • reverse
          • setintersection
          • setproduct
          • setunion
          • slice
          • sort
          • values
          • zipmap
          • base64decode
          • base64encode
          • csvdecode
          • jsondecode
          • jsonencode
          • urlencode
          • yamldecode
          • yamlencode
          • abspath
          • basename
          • dirname
          • file
          • fileexists
          • fileset
          • pathexpand
          • templatefile
          • formatdate
          • timeadd
          • timestamp
          • legacy_isotime
          • legacy_strftime
          • bcrypt
          • md5
          • rsadecrypt
          • sha1
          • sha256
          • sha512
          • uuidv4
          • uuidv5
          • cidrhost
          • cidrnetmask
          • cidrsubnet
          • cidrsubnets
          • can
          • convert
          • try
      • Variables
      • Locals
      • Contextual Variables
      • Data Sources
      • Path Variables
      • Syntax
      • Only Except
      • Expressions
      • JSON Syntax
      • Overview
      • Builders
      • Communicators
      • Engine
      • Post-Processors
      • Provisioners
      • User Variables

    • Overview
    • SSH
    • WINRM
    • Overview
    • File
    • Null
    • Custom
    • Community-Supported
    • Overview
      • Overview
      • Iteration
      • Image
      • Image-Deprecated
    • Overview
    • Breakpoint
    • File
    • PowerShell
    • Shell
    • Shell (Local)
    • Windows Shell
    • Windows Restart
    • Custom
    • Community-Supported
    • Overview
    • Artifice
    • Compress
    • Checksum
    • Manifest
    • Shell (Local)
    • Community-Supported
  • External Plugins

  • Installing Packer
  • Configuring Packer

    • Overview
      • Overview
      • Custom Builders
      • Custom Post-Processors
      • Custom Provisioners
      • Custom Data Sources
    • HCP Packer Support
  • Integration Program

  • Debugging
  • HCP Packer
Type '/' to Search

»The post-processors block

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.hcl
build {
  # ...
  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 artifact
      files = ["artifice.txt"]
    }
    post-processor "checksum" { # checksum artifice.txt
      checksum_types = [ "md5", "sha512" ] # checksum the artifact
      keep_input_artifact = true           # keep the artifact
    }
  }

}
# builds.pkr.hcl
build {
  # ...
  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 artifact
      files = ["artifice.txt"]
    }
    post-processor "checksum" { # checksum artifice.txt
      checksum_types = [ "md5", "sha512" ] # checksum the artifact
      keep_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.hcl
build {
  # ... build image
  post-processor "checksum" { # checksum image
    checksum_types = [ "md5", "sha512" ] # checksum the artifact
  }

  post-processor "amazon-import" { # upload image to AWS
  }

  post-processor "googlecompute-import" { # upload image to GCP
  }
}
# builds.pkr.hcl
build {
  # ... build image
  post-processor "checksum" { # checksum image
    checksum_types = [ "md5", "sha512" ] # checksum the artifact
  }

  post-processor "amazon-import" { # upload image to AWS
  }

  post-processor "googlecompute-import" { # upload image to GCP
  }
}
# builds.pkr.hcl
build {
  # ... build image
  post-processors {
    post-processor "checksum" { # checksum image
      checksum_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.hcl
build {
  # ... build image
  post-processors {
    post-processor "checksum" { # checksum image
      checksum_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.

github logoEdit this page
IntroGuidesDocsCommunityPrivacySecurityPress KitConsent Manager