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
Official
HCP Packer Ready

»HCP Packer Image Data Source

Type: hcp-packer-image

The HCP Packer Image Data Source retrieves information about an image from the HCP Packer registry. This information can be used to provide a source image to various Packer builders.

To get started with HCP Packer, refer to the HCP Packer documentation or try the Get Started with HCP Packer collection on HashiCorp Learn.

Note: You will receive an error if you try to reference metadata from a deactivated or deleted registry. An administrator can manually deactivate or delete a registry, and HCP Packer automatically deactivates registries with billing issues. Contact HashiCorp Support with questions.

»Basic Example

Below is a fully functioning example. It stores information about an image, which can then be parsed and accessed as a variable.

data "hcp-packer-image" "example" {
  bucket_name = "hardened-ubuntu-16-04"
  iteration_id = "${data.hcp-packer-iteration.hardened-source.id}"
  cloud_provider = "aws"
  region = "us-east-1"
}
data "hcp-packer-image" "example" {
  bucket_name = "hardened-ubuntu-16-04"
  iteration_id = "${data.hcp-packer-iteration.hardened-source.id}"
  cloud_provider = "aws"
  region = "us-east-1"
}

»Full Example

This data source can be used in conjunction with the hcp-packer-iteration data source to retrieve an image ID using a channel. You provide the channel name to the iteration data source, then use the iteration source in the image data source, then use the image data source inside your source block.

# Retrieves information about the HCP Packer "iteration"; an "iteration" can be
# thought of as all the metadata created by a single call of `packer build`.
data "hcp-packer-iteration" "hardened-source" {
  bucket_name = "hardened-ubuntu-16-04"
  channel = "packer-test"
}

# Retrieves information about the HCP Packer "image"; an image can be thought
# of as all the metadata (including the artifact names) created by a single
# "source" builder; this can include multiple images so we provide a cloud
# region to disambiguate.
data "hcp-packer-image" "foo" {
  bucket_name = "hardened-ubuntu-16-04"
  iteration_id = data.hcp-packer-iteration.hardened-source.id
  cloud_provider = "aws"
  region = "us-east-1"
}

# This source uses the output from a previous Packer build. By using the
# HCP Packer registry in this way, you can easily create build pipelines where
# a single base image can be customized in multiple secondary layers.
source "amazon-ebs" "packer-secondary" {
  source_ami       = data.hcp-packer-image.foo.id
  # ...
}
# Retrieves information about the HCP Packer "iteration"; an "iteration" can be
# thought of as all the metadata created by a single call of `packer build`.
data "hcp-packer-iteration" "hardened-source" {
  bucket_name = "hardened-ubuntu-16-04"
  channel = "packer-test"
}

# Retrieves information about the HCP Packer "image"; an image can be thought
# of as all the metadata (including the artifact names) created by a single
# "source" builder; this can include multiple images so we provide a cloud
# region to disambiguate.
data "hcp-packer-image" "foo" {
  bucket_name = "hardened-ubuntu-16-04"
  iteration_id = data.hcp-packer-iteration.hardened-source.id
  cloud_provider = "aws"
  region = "us-east-1"
}

# This source uses the output from a previous Packer build. By using the
# HCP Packer registry in this way, you can easily create build pipelines where
# a single base image can be customized in multiple secondary layers.
source "amazon-ebs" "packer-secondary" {
  source_ami       = data.hcp-packer-image.foo.id
  # ...
}

»Configuration Reference

Configuration options are organized below into two categories: required and optional. Within each category, the available options are alphabetized and described.

»Required:

  • bucket_name (string) - The name of the bucket your image is in.

  • iteration_id (string) - The name of the iteration Id to use when retrieving your image

  • cloud_provider (string) - The name of the cloud provider that your image is for. For example, "aws" or "gce".

  • region (string) - The name of the cloud region your image is in. For example "us-east-1".

There are currently no optional fields for this datasource, though we intend to add filtering fields in the future.

»Output Fields:

  • cloud_provider (string) - The name of the cloud provider that the image exists in. For example, "aws", "azure", or "gce".

  • component_type (string) - The specific Packer builder or post-processor used to create the image.

  • created_at (string) - The date and time at which the image was created.

  • build_id (string) - The id of the build that created the image. This is a ULID, which is a unique identifier similar to a UUID. It is created by the HCP Packer Registry when an build is first created, and is unique to this build.

  • iteration_id (string) - The iteration id. This is a ULID, which is a unique identifier similar to a UUID. It is created by the HCP Packer Registry when an iteration is first created, and is unique to this iteration.

  • packer_run_uuid (string) - The UUID associated with the Packer run that created this image.

  • id (string) - ID or URL of the remote cloud image as given by a build.

  • region (string) - The cloud region as given by packer build. eg. "ap-east-1". For locally managed clouds, this may map instead to a cluster, server or datastore.

  • labels (map[string]string) - The key:value metadata labels associated with this build.

github logoEdit this page
IntroGuidesDocsCommunityPrivacySecurityPress KitConsent Manager