Skip to content
Tutorials Center
My learning

Topics

Lesson 24 of 36 ยท Post-processors and Pipelines

The Manifest Post-processor and Image Metadata

Use the Packer manifest post-processor to record AMI ids, build times and custom data in JSON, parse artifact ids per region, and pass image ids to Terraform or deployment steps.

Packer builds produce identifiers: an AMI id per region, a GCE image name, a container digest. Those identifiers are the output your deployment needs, yet they only appear in the console log. Scraping logs is brittle. The manifest post-processor writes a small JSON file with every artifact, so scripts and pipelines can read results reliably.

Packer is not available on this site. The HCL is read-only; the JavaScript examples parse a manifest shaped like a real one so you can practise reading it. The sample data is made up.

Adding the manifest

HCL
build {
  sources = [
    "source.amazon-ebs.base",
    "source.googlecompute.debian",
  ]

  post-processor "manifest" {
    output     = "packer-manifest.json"
    strip_path = true
    custom_data = {
      git_sha = var.git_sha
      version = var.version
      pipeline = var.pipeline_url
    }
  }
}
  • output defaults to packer-manifest.json in the current directory.
  • strip_path removes directory parts from file artifacts so the manifest does not leak local paths.
  • custom_data is a map of strings copied into every entry. Put anything a later step needs: commit SHA, semantic version, pipeline URL, base image id.

The file format

The manifest has a builds list and a last_run_uuid:

JSON
{
  "builds": [
    {
      "name": "base",
      "builder_type": "amazon-ebs",
      "build_time": 1735725600,
      "files": null,
      "artifact_id": "eu-central-1:ami-0aaa1111,eu-west-1:ami-0bbb2222",
      "packer_run_uuid": "6c1c7b0e-0000-4000-8000-000000000000",
      "custom_data": { "git_sha": "a1b2c3d", "version": "1.4.0" }
    }
  ],
  "last_run_uuid": "6c1c7b0e-0000-4000-8000-000000000000"
}

Important details:

  • Each build appends an entry; the file is not replaced between runs. last_run_uuid identifies the most recent run so you can filter to it. Delete the file before a build if you want a clean file.
  • For AWS the artifact_id is a comma-separated list of region:ami pairs. Other builders use their own format.
  • build_time is a Unix timestamp in seconds.
  • All custom_data values are strings.

Reading it in a pipeline

With jq, to get the AMI id for a region of the latest run:

Terminal
jq -r '.last_run_uuid as $run
  | .builds[] | select(.packer_run_uuid == $run)
  | .artifact_id | split(",")[] | select(startswith("eu-central-1:")) | split(":")[1]' packer-manifest.json

That id can be written to an SSM parameter, passed to Terraform with -var ami_id=... or posted to a chat channel. This hand-off from the image pipeline to the infrastructure pipeline is the main purpose of the manifest. See image versioning and promotion for patterns built on it.

Beyond manifest: other metadata

  • Tags and labels on the artifact itself (AMI tags, GCE image_labels, Docker LABEL) travel with the image and are visible in the cloud console.
  • HCP Packer (the registry service) stores build metadata centrally, with channels and ancestry; see the versioning lesson.
  • A shell-local post-processor can post a message or call an API with the manifest content.

Try it: parse a manifest

JS Read artifact ids from a manifest (stand-in)

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Try it: generate Terraform variables

JS Manifest to tfvars (stand-in)

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Common mistakes

  1. Forgetting that the file appends, then reading the first entry (an old build).
  2. Parsing the AWS artifact_id as a single AMI when several regions are present.
  3. Committing packer-manifest.json to Git. It is a build output; publish it as a pipeline artifact instead.
  4. Putting secrets into custom_data; the file is plain text.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does the manifest post-processor write?

    packer-manifest.json holds builds with artifact ids, times and custom data.
  2. 2. How do you find the entries of the most recent run?

    The file appends across runs, so filter by the last run's uuid.
  3. 3. What format does the amazon-ebs artifact_id use for several regions?

    For example eu-central-1:ami-123,eu-west-1:ami-456.
  4. 4. Which belongs in custom_data?

    custom_data is plain text; use it for non-secret build context.

Summary

  • manifest records artifacts and custom data as JSON so later steps do not scrape logs.
  • Entries append across runs; use last_run_uuid to filter.
  • AWS artifact ids are region:ami pairs; parse them per region.
  • Treat the manifest as a pipeline artifact, not a committed file, and keep secrets out of it.

Next: Checksum, compress and artifice