Packer doesn't see my environment variables?

3.2k views Asked by At

I have AWS_ACCESS_KEY and AWS_SECRET_KEY key/value pairs defined in my environment (I see them via env command on same terminal I run Packer), and I want Packer to use them in a build script.

My Packer file looks like

{
  "variables" : {
    "aws_access_key" : "{{ env `AWS_ACCESS_KEY` }}",
    "aws_secret_key" : "{{ env `AWS_SECRET_KEY` }}",
    ...
  },
  ...
  "provisioners" : [
    {
      "type" : "shell",
      "environment_vars": "AWS_ACCESS_KEY={{ user `aws_access_key` }}",
      "environment_vars": "AWS_SECRET_KEY={{ user `aws_secret_key` }}",
      "execute_command": "{{.Vars}} sudo -E -S bash '{{.Path}}'",
      "script" : "./ecs_prepare_master.sh"
    }
  ]
}

The ecs_prepare_master.sh scripts has these steps, and they're showing as blank. I even tried passing the key/value pairs along with my packer build ... command line to no avail.

echo "access=$AWS_ACCESS_KEY"
echo "secret=AWS_SECRET_KEY"

What's missing?

1

There are 1 answers

0
Chris F On BEST ANSWER

Ah, the syntax for multiple environment variables is

"environment_vars": [
    "AWS_ACCESS_KEY={{ user `aws_access_key` }}",
    "AWS_SECRET_KEY={{ user `aws_secret_key` }}"
]