Skip to content
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

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

Closed
rickard-von-essen opened this issue Jul 10, 2018 · 6 comments · Fixed by #7005
Labels
bug core Core components of Packer docs

Comments

@rickard-von-essen
Copy link
Collaborator

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

@SwampDragons
Copy link
Contributor

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

@SwampDragons
Copy link
Contributor

Scratch that -- introduced in 0.12.1

@SwampDragons
Copy link
Contributor

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.

@SwampDragons
Copy link
Contributor

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.

@rickard-von-essen
Copy link
Collaborator Author

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.

@ghost
Copy link

ghost commented Mar 30, 2020

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.

@ghost ghost locked and limited conversation to collaborators Mar 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug core Core components of Packer docs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants