Packer under Windows 10 doesn't override default variables

30 views
Skip to first unread message

Chris Marks

unread,
Oct 19, 2016, 7:32:23 PM10/19/16
to Packer
Hi,
I'm running into something that I'm not sure I understand.  Here's my (stripped down for example) use case:  I want to create an AMI where the name includes the environment it is built for (test, prod, etc).  Here's the packer file (named testVar.json):
{
  "variables": {
    "aws_access_key": "",
    "aws_secret_key": "",
    "cpe_env": "test"
  },
  "builders": [{
    "type": "amazon-ebs",
    "access_key": "{{user `aws_access_key`}}",
    "secret_key": "{{user `aws_secret_key`}}",
    "region": "us-west-2",
    "source_ami": "ami-b04e92d0",
    "instance_type": "t2.micro",
    "ssh_username": "ec2-user",
    "ami_name": "TestAMI-{{isotime \"20060102-1504\"}}-{{user `cpe_env`}}",
    "vpc_id": "someVPC",
    "subnet_id": "someSubnet"
  }]
}


When I run the following Packer command on Windows 10, I end up with an AMI name like "TestAMI-20161019-2241-test".  When I run the same command on Linux (Amazon Linux), I end up with an AMI name like "TestAMI-20161019-2241-prod".  I think this is a bug in Packer, but wanted to check here before submitting in case I'm missing something.

packer build -var 'aws_access_key=someAccessKey' -var 'aws_secret_key=someSecretKey' -var 'cpe_env=prod' testVar.json

I've tried this Packer 0.10.1 and 0.10.2.

Thanks,
topher

Rickard von Essen

unread,
Oct 22, 2016, 7:40:39 AM10/22/16
to packe...@googlegroups.com
Do you run it in cmd or Powershell? I'm pretty sure that is working and is not a bug. But I don't have any Windows machine to test on. What happens if you drop the quotes. I would suspect that it's just the windows shell that parses things different.

Try this template (test.json):
{
  "variables": { "avar": "testing" },
  "builders": [ {
    "type": "file",
    "content": "{{ user `avar` }} World!",
    "target": "file.txt"
  } ]
}

And run
packer build -var avar=Hello test.json; cat file.txt 

--
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/c345373e-abe9-491f-bd43-3d4d71f99083%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages