-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HCL templates cannot call functions for variable defaults #9430
Comments
Packer does not yet support defaults in variables, so it's not possible to get a consistent timestamp to use as part of the AMI and a tag. Since AMI name must be unique, it's better to put the build timestamp there rather than in a tag. This bug is tracked upstream as hashicorp/packer#9430.
Hey @jen20, quoting this message here hashicorp/terraform#17229 (comment)
For this purpose I would recommend instead using a local variable: locals {
packerstarttime = formatdate("YYYY-MM-DD-hhmm", timestamp())
# Also here I believe naming this variable `buildtime` could lead to
# confusion mainly because this is evaluated a 'parsing-time'.
} I'm going to go ahead and close this issue, please do not hesitate asking more questions, thanks for trying Packer HCL2 !! |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Overview of the Issue
Using the new HCL template format, there is no way to define a variable which calls a function, which is a regression from the JSON template format.
This is useful when determining a consistent value for (as an example) the time at which an image was built to be used in both the AMI name and also an AMI and snapshot tag.
In the JSON syntax, the following works:
The
buildtime
variable can then be interpolated at other points in the template.Reproduction Steps
In an HCL template:
Packer version
Packer v1.6.0
Operating system and Environment details
macOS 10.15.5, Packer v1.6.0, AWS
The text was updated successfully, but these errors were encountered: