Packer works in AWS by spinning up an instance in your AWS account, configuring that instance, then creating an AMI from it which can be stored as an artifact in Atlas.
In order to do this, Packer only needs your AWS credentials, everything else is done in the Packer template. However, there can be an issue SSH'ing in to the instance that was created depending on how your AWS setup is configured. You may see a Packer build error similar to amazon-ebs: Timeout waiting for SSH.
.
If you have an AWS EC2-Classic account (created after 12/04/2013), or will be launching these instances into a VPC, there are a few steps below you'll want to follow.
The Amazon links in these steps will refer to a VPC in the us-east-1 region. There are 2 main parts, the Networking and the Packer template.
Below are steps to ensure your networking in AWS is setup to allow Packer to SSH into instances created in your VPC. If you already have one or all of these components, there is no need to re-create, just verify each piece exists. If one or more of these components do not exist, use the Terraform network module to setup a complete VPC for you.
-
Create a VPC with the CIDR block of your choice, we'll use
10.0.0.0/24
You should see your new VPC
-
You should see your new Internet Gateway
-
Attach Internet Gateway to VPC
You see see your attached Internet Gateway
-
Add Route to Route Table with a destination of
0.0.0.0/0
-
Add Subnet with a CIDR block of your choice, we'll use
10.0.0.0/24
You should see your new Subnet
If you're using an AWS EC2-Classic account, or launching Packer instances in a VPC, you'll need to add a few things to your Packer template.
Add the vpc_id
and subnet_id
you just created (or grab your existing). In our case it was a vpc_id of vpc-1fea007b
and a subnet_id
of subnet-8f1e5ba4
. You'll also want to set ssh_private_ip
to false
and associate_public_ip_address
to true
. See the below example Packer amazon-ebs
builder.
"builders": [{
"type": "amazon-ebs",
"access_key": "{{user `aws_access_key`}}",
"secret_key": "{{user `aws_secret_key`}}",
"region": "us-east-1",
"vpc_id": "vpc-1fea007b",
"subnet_id": "subnet-8f1e5ba4",
"ssh_username": "{{user `ssh_username`}}",
"ssh_private_ip": false,
"associate_public_ip_address": true,
"instance_type": "t2.micro",
"source_ami": "ami-9a562df2",
"ami_name": "test {{timestamp}}",
"ami_description": "Test AMI",
"run_tags": {
"ami-create": "test"
},
"tags": {
"ami": "test"
}
}],