Skip to content

Commit

Permalink
Add the deprecation warning and update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
devashish-patel authored and lbajolet-hashicorp committed Jan 26, 2024
1 parent dbde011 commit b6144f9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
8 changes: 6 additions & 2 deletions hcl2template/types.packer_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package hcl2template

import (
"fmt"
"log"
"sort"
"strings"

Expand Down Expand Up @@ -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, `\`, `/`)),
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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"
Expand All @@ -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}"
}
}
Expand Down

0 comments on commit b6144f9

Please sign in to comment.