Am trying to add a suffix of %Y-%m-%d suffix to the generated image. However I get an error about formatdate not defined error. Am using Packer v1.10.2
There are two alternatives for string interpolation with HCL2: native HCL2, and legacy (inherited from JSON-only templates).
The legacy format is essentially what you’ve done with {{.BuildName}}, it’s a form of mustache/go templating with some keywords for accessing functions or user-provided variables. Please refer to our docs for more information on the subject.
If you’re using HCL2, legacy template interpolation is still allowed (and in some cases necessary for technical reasons), but is discouraged in favour of HCL native string interpolation with ${}.
In your case for invoking formatdate this is likely what you’re aiming for.
Typically an updated template for your use-case would look like this:
Note: for reference, BuildName is still interpolated using legacy-JSON syntax since it’s runtime-level information that is interpolated by the plugins, which lack HCL2 interpolation capabilities.