packer-plugin-amazon
packer-plugin-amazon copied to clipboard
packer fails to validate `deprecate_at` unless it's a literal string
Overview of the Issue
I am using the amazon-ebs builder with the amazon-ami data source, to build a custom AMI based off an existing upstream AMI.
I've found that I can't run packer validate if I set deprecate_at to anything other than a literal string. My upstream AMI is replaced on a schedule, so I wanted to set deprecate_at to e.g. timeadd(data.amazon-ami.source.creation_date, duration). But when I do, I get an error like the following:
Error: 1 error(s) occurred:
* deprecate_at is not a valid time. Expect time format: YYYY-MM-DDTHH:MM:SSZ
I think this is a bug:
- If I cause the result to be written to a file instead, I see that the written date/time matches the expected format.
- If I replace
timeadd(...)with the value written to the file, it validates. - If I replace
timeadd(data.amazon-ami...)withtimeadd(timestamp(), ...), it validates. - If I just run
packer build example.pkr.hclit works fine, setting the expected deprecation time.
This blocks me because my CI routine runs packer validate on the template, so even though packer build would work, CI fails. I would have to work around it by calculating the deprecation_time outside Packer and passing the result in as a variable.
Maybe this is a Packer problem? The data source is not evaluated by packer validate, and the parameter expects a particularly-formatted string, so there would be no way to ensure a calculated value is valid. I wonder if, instead of failing to validate, this could issue a warning instead?
Reproduction Steps
See gist at https://gist.github.com/saxonww/d237f1ff2a3292cf916b02d85eca8cb5
Plugin and Packer version
Packer v1.10.1
Plugin version v1.3.2
Simplified Packer Buildfile
See gist at https://gist.github.com/saxonww/d237f1ff2a3292cf916b02d85eca8cb5
Operating system and Environment details
A Docker container based on the following:
$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
Architecture is x86_64.
Log Fragments and crash.log files
Setting PACKER_LOG=1 doesn't yield anything useful.