Packer: User variables specified with -var doesn't have to be declared in the variables block

Created on 10 Jul 2018  ยท  6Comments  ยท  Source: hashicorp/packer

Example template:

https://github.com/awslabs/amazon-eks-ami/blob/master/eks-worker-al2.json

$ packer validate eks-worker-al2.json
Template validation failed. Errors are shown below.

Errors validating build 'amazon-ebs'. 1 error(s) occurred:

* A source_ami or source_ami_filter must be specified
$ packer validate -var source_ami_id=ssss eks-worker-al2.json
Template validated successfully.

This contradicts what the documentation says:

User variables must first be defined in a variables section within your template. Even if you want a user variable to default to an empty string, it must be defined. This explicitness helps reduce the time it takes for newcomers to understand what can be modified using variables in your template.

See User Variables - Usage

bug core docs

All 6 comments

Tested on a bunch of old binaries; this was first broken in 1.0.0.

Scratch that -- introduced in 0.12.1

Actually, I was misreading output; this has been broken since at least 0.12, but probably before. I'm not going to search further back for where this was introduced, if it ever worked.

I ended up going back a bit further; this has never worked as you're interpreting as far as I can tell.

We can either change the code or change the docs. To be honest I'm leaning towards changing the docs, since I'm worried changing this to match the documentation will break a _lot_ of templates.

I agree, if this have been working like this since the dark ages let's keep it as it is and correct the docs.

If it's easy to add i think it would be great if we logged a warning/info when a undeclared variable is passed. This gives us a better position if we want to change this in the future and helps troubleshooting misspellings etc.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tleyden picture tleyden  ยท  3Comments

Tensho picture Tensho  ยท  3Comments

mwhooker picture mwhooker  ยท  3Comments

Nikoos picture Nikoos  ยท  3Comments

shashanksinha89 picture shashanksinha89  ยท  3Comments