diff --git a/hcl2template/types.packer_config.go b/hcl2template/types.packer_config.go index b88dfe4d3..f8343cfd6 100644 --- a/hcl2template/types.packer_config.go +++ b/hcl2template/types.packer_config.go @@ -5,6 +5,7 @@ package hcl2template import ( "fmt" + "log" "sort" "strings" @@ -110,8 +111,9 @@ func (cfg *PackerConfig) EvalContext(ctx BlockContext, variables map[string]cty. }), buildAccessor: cty.UnknownVal(cty.EmptyObject), packerAccessor: cty.ObjectVal(map[string]cty.Value{ - "version": cty.StringVal(cfg.CorePackerVersionString), - "iterationID": cty.UnknownVal(cty.String), + "version": cty.StringVal(cfg.CorePackerVersionString), + "iterationID": cty.UnknownVal(cty.String), + "versionFingerprint": cty.UnknownVal(cty.String), }), pathVariablesAccessor: cty.ObjectVal(map[string]cty.Value{ "cwd": cty.StringVal(strings.ReplaceAll(cfg.Cwd, `\`, `/`)), @@ -122,6 +124,8 @@ func (cfg *PackerConfig) EvalContext(ctx BlockContext, variables map[string]cty. iterID, ok := cfg.HCPVars["iterationID"] if ok { + log.Printf("[WARN] Deprecation: Contextual Variable `iterationID` has been deprecated packer context. " + + "Please use `versionFingerprint` variable instead.") ectx.Variables[packerAccessor] = cty.ObjectVal(map[string]cty.Value{ "version": cty.StringVal(cfg.CorePackerVersionString), "iterationID": iterID, diff --git a/website/content/docs/templates/hcl_templates/contextual-variables.mdx b/website/content/docs/templates/hcl_templates/contextual-variables.mdx index b755e1082..c091313c6 100644 --- a/website/content/docs/templates/hcl_templates/contextual-variables.mdx +++ b/website/content/docs/templates/hcl_templates/contextual-variables.mdx @@ -132,6 +132,8 @@ parenthesis may through off your shell escaping otherwise. # HCP Packer Iteration ID +~> **Note**: Deprecation: Contextual Variable `iterationID` has been deprecated packer context. Please use `versionFingerprint` variable instead. + If your build is pushing metadata to the HCP Packer registry, this variable is set to the value of the Iteration ID associated with this run. @@ -145,6 +147,22 @@ source "amazon-ebs" "cannonical-ubuntu-server" { } ``` +# HCP Packer Version Fingerprint + +If your build is pushing metadata to the HCP Packer registry, this variable is +set to the value of the Version Fingerprint associated with this run. + +```hcl +source "amazon-ebs" "cannonical-ubuntu-server" { + ami_name = "packer-example" + // ... + run_volume_tags = { + hcp_version_fingerprint = packer.versionFingerprint + } +} +``` + + ```shell-session ==> vanilla.amazon-ebs.cannonical-ubuntu-server: Adding tags to source instance vanilla.amazon-ebs.cannonical-ubuntu-server: Adding tag: "Name": "Packer Builder" @@ -158,6 +176,8 @@ You can also add this value to post-processors, for example to add to a manifest output = "manifest.json" strip_path = true custom_data = { + version_fingerprint = "${packer.versionFingerprint}" + // `packer.iterationID` has been deprecated. iteration = "${packer.iterationID}" } }