Variable file option in packer

2,021 views
Skip to first unread message

Sandeep Sharma

unread,
Nov 30, 2015, 7:31:35 AM11/30/15
to Packer
Hi


I have three aws accounts so trying to use variable file for AMI permission. 

variables.json

{
"ami_users" : ["1111111111111", "222222222222", "333333333333"],
"ami_regions": ["us-east-1", "eu-west-1"]
}

]# packer build -var-file=variables.json /tmp/test.json
invalid value "variables.json" for flag -var-file: Error reading variables in 'variables.json': json: cannot unmarshal array into Go value of type string


Is this correct?

Regards
Sandeep Sharma

Bad Santa

unread,
Apr 13, 2018, 8:39:03 PM4/13/18
to Packer
I also have this issue. Were you able to resolve it?

Rickard von Essen

unread,
Apr 14, 2018, 7:02:55 AM4/14/18
to packe...@googlegroups.com
Variables should always be strings. Array type options which gets a variable splits them on comma. You variables.json should be:

{
  "ami_users" : "1111111111111,222222222222,333333333333",
  "ami_regions": "us-east-1,eu-west-1"
}


And in your packer template you use them like this:

{
  "variables": {
    "ami_users": null,
    "ami_regions": null
  },
  "builders": [
    {
       "type": "amazon-ebs",
       "ami_users": "{{ user `ami_users` }}"
     }
  ]

See


--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/69f3e0be-fb7d-4875-9903-5b65f75a01b6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Todd Foley

unread,
Mar 13, 2019, 6:49:04 PM3/13/19
to Packer
what happens when you have a nested comma? 
example: 

{
"variables": {
"changes": "CMD [\"/bar\"],ENTRYPOINT [\"/foo\",\"--\"]"
},

"builders": [
{
"type": "docker",
"image": "ubuntu:16.04",
"run_command": ["-d", "{{.Image}}"],
"changes": "{{ user `changes`}}",
"commit": true
}
],
"post-processors": [
[
{
"type": "docker-tag",
"repository": "my/ubuntu",
"tag": "16.04"
}
]
]
}


To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.

Rickard von Essen

unread,
Mar 14, 2019, 12:48:18 AM3/14/19
to packe...@googlegroups.com
I don't that will work, it will split on all commas. 

JP Bourget

unread,
Apr 1, 2019, 12:58:40 PM4/1/19
to Packer
This happened to me and it was because for a var-file you don't need the "variables": {... 

just open and close { }... 
so {
    "var1": "value"
     }

To unsubscribe from this group and stop receiving emails from it, send an email to packe...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages