Re: [packer] How does variable validation actually work?

18 views
Skip to first unread message

Rickard von Essen

unread,
Oct 19, 2018, 4:02:09 PM10/19/18
to packe...@googlegroups.com
Setting a value to null in a vars file have no effect. If you want to force it to specified on the command line, don't include it. Setting it to an empty string will pass that (valid) value.

On Fri, Oct 19, 2018 at 9:20 PM Justin Metz <4jm...@gmail.com> wrote:
Hi All,

I have been using Packer for quite some time now and the way variables are evaluated\validated at runtime has always been a point of confusion.  I have tried many different combinations of assigning a blank string "" value and a null value, but I can't seem to get the native validation to fail if a variable is of those values at runtime.  I pass in a variables.json file with matching properties and set those to "" and null as well, with the same result.  I've even passed in just a subset of the variables that exist in the target template and I don't get anything.  At this point in time, I'm using V1.3.1 but I had the same results with previous versions. 
My main goal is to have packer validate that the variable is empty and fail vs it just going through with a blank value and things not working out as expected..

The documentation for packer validate shows this, which leads me to believe that if I force a value to null it will trigger an errror:
"If the default value is null, then the user variable will be required. This means that the user must specify a value for this variable or template validation will fail."

Here is an example of one of the things I've tried.  Please let me know what I'm doing wrong, it's driving me a bit nutty. :)

--- variables.json content being passed in as a file (some values left blank on purpose and one property is left out.  A mix of empty strings and nulls)---

{
    "aws_access_key":"11111111111",
    "aws_secret_key":"111111111",
    "ssh_keypair_name":"",
    "ssh_private_key_file":null,
    "destination_ami_name": ""
}



--- variables in packer.json template
(A mix of empty strings and nulls)---

"variables":
{
    "aws_access_key":"",
    "aws_secret_key":"",
    "ssh_keypair_name":
null,
    "ssh_private_key_file":"",
    "destination_ami_name": "",
    "source_ami_name": null
},


Any advice would be greatly appreciated...

J

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/9398630c-7c60-4a14-844f-fc900473a4e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

J Metz

unread,
Oct 19, 2018, 4:13:20 PM10/19/18
to packe...@googlegroups.com
Thanks Rickard.. It seems I was obviously making that one a lot more difficult that it was by sending in values that were blank strings vs null.

Reply all
Reply to author
Forward
0 new messages