Any way to access the version of Packer in a build?

I’m starting to use Packer to generate some AMIs and would like to add some metadata tags to the resulting images. In particular, I’d like to annotate the images with the version of Packer that they were built with.

I wasn’t able to find any programmatic way to access that information inside the build, so I ended up defining it as a variable that I just pass in:

packer build -var 'packer_version=$(packer version)' my_image.pkr.hcl

That works fine, but is there a more direct way to achieve this that I’m missing?

Thanks in advance!


Ah, it looks like it actually ended up as packer.version, a contextual variable: Contextual Variables - HCL Configuration Language | Packer by HashiCorp

Thanks for the pointer @Wolfsrudel !

You are welcome and thank you, too. My solution seems to work for the “still-use-json” dudes. :smiley:

1 Like