Create multiple regions in the same packer run

2,848 views
Skip to first unread message

richard....@teamaol.com

unread,
Feb 18, 2016, 12:35:54 PM2/18/16
to Packer
Hi,

I was wondering if anyone has been able to use packers parallel build scenario to produce AWS AMI's for different regions. I have a system where I am running a build (in AWS jenkins) and then calling Packer. I want to produce AMI's for 3 regions (us-east, us-west, apac) from that same build. We are using a combo of Ansible/EtcD for provisioning and configuration but when I try to specify multiple regions in the 'builders section, something like this (stealing the example from the packer docs website)

 "builders": [{
    "type": "amazon-ebs",
    "access_key": "{{user `aws_access_key`}}",
    "secret_key": "{{user `aws_secret_key`}}",
    "region": "us-east-1",
    "source_ami": "ami-72b9e018",
    "instance_type": "t2.micro",
    "ssh_username": "ubuntu",
    "ami_name": "packer-example {{timestamp}}"
  },{
    "type": "amazon-ebs"
    "access_key": "{{user `aws_access_key2`}}",
    "secret_key": "{{user `aws_secret_key2`}}",
    "region": "us-west-1", 
    "source_ami": "ami-88aebe564",
    "instance_type": "t2.micro", 
    "ssh_username": "ubuntu"
    "ami_name": "packer-example2 {{timestamp}}"
 }]

etc....it fails ...


Does anyone know how to do this?

Thanks

Richard




Chris Bednarski

unread,
Feb 18, 2016, 3:25:00 PM2/18/16
to Packer
Hi Richard,

Each build has to have a unique name. By default the name is the same as the builder type (amazon-ebs in this case) so you will need to add a name block to each bulid e.g. "name":"aws-region1". Another way to do this is to use only one build and copy the AMI when you're done using https://www.packer.io/docs/builders/amazon-ebs.html#ami_regions

Cheers!

Chris

Alvaro Miranda Aguilera

unread,
Feb 18, 2016, 7:25:12 PM2/18/16
to packe...@googlegroups.com

On Fri, Feb 19, 2016 at 6:35 AM, <richard....@teamaol.com> wrote:
 "builders": [{
    "type": "amazon-ebs",
    "access_key": "{{user `aws_access_key`}}",
    "secret_key": "{{user `aws_secret_key`}}",
    "region": "us-east-1",
    "source_ami": "ami-72b9e018",
    "instance_type": "t2.micro",
    "ssh_username": "ubuntu",
    "ami_name": "packer-example {{timestamp}}"
  },{
    "type": "amazon-ebs"
    "access_key": "{{user `aws_access_key2`}}",
    "secret_key": "{{user `aws_secret_key2`}}",
    "region": "us-west-1", 
    "source_ami": "ami-88aebe564",
    "instance_type": "t2.micro", 
    "ssh_username": "ubuntu"
    "ami_name": "packer-example2 {{timestamp}}"
 }]


Expanded example of option 1 from Chris:

 "builders": [{
    "type": "amazon-ebs",
    "name": "us-east-1",
    "access_key": "{{user `aws_access_key`}}",
    "secret_key": "{{user `aws_secret_key`}}",
    "region": "us-east-1",
    "source_ami": "ami-72b9e018",
    "instance_type": "t2.micro",
    "ssh_username": "ubuntu",
    "ami_name": "packer-example {{timestamp}}"
  },{
    "type": "amazon-ebs"
    "name": "us-west-1",
    "access_key": "{{user `aws_access_key2`}}",
    "secret_key": "{{user `aws_secret_key2`}}",
    "region": "us-west-1", 
    "source_ami": "ami-88aebe564",
    "instance_type": "t2.micro", 
    "ssh_username": "ubuntu", <- missed comma
    "ami_name": "packer-example2 {{timestamp}}"
 }]

More info about this is here:

Alvaro.
Reply all
Reply to author
Forward
0 new messages