Skip to content

Variables

There are multiple ways use variables with Packer Templates.

From cmd line

packer build base.json -var 'region=eu-west-1'

From a file

packer build base.json -var-file env.json

Where the env.json looks like:

{
  "instance_type": "t2.micro",
  "vpc_id": "vpc-xxxxxxx",
  "subnet_id": "subnet-xxxxxxx",
  "ami_users": "xxxxxxxxxx",
  "aws_region": "eu-west-1"
}

From Environmental Variables

Any environmental Variable can be used in the template, to get AWS_ACCESS_KEY_ID:

{{env `AWS_ACCESS_KEY_ID`}}

From Consul

You can access key/value in consul:

{{ consul_key `my/lovely/horse` }}

From Vault

And Secret or sensitive variables from Hashicorp Vault:

{{ vault `/my/secret/lovely` `horse`}}