5

I am trying to make a packer image, but on our amazon account we DO NOT have a default VPC. It has been removed. And have been getting this error when trying to pack the image:

==> amazon-instance: Inspecting the source AMI...
==> amazon-instance: Creating temporary keypair: packer 54cfd9c9-61ef-5f8f-4091-d27e731a8a4d
==> amazon-instance: Creating temporary security group for this instance...
==> amazon-instance: No default VPC for this user (VPCIdNotSpecified)
==> amazon-instance: Deleting temporary keypair...
Build 'amazon-instance' finished.

Therefore I am supposed to specify a default VPC id or subnet id.

I have tried both,

{
  "variables": {
    "vpc_id ": "vpc-962438f4",
    "subnet_id": "subnet-1c5d5c68"
    },
  "builders": [{
    "type": "amazon-instance",
    "access_key": "somekey"
    "secret_key": "somekey"
    "account_id": "AccountIDNUMBER"
    "region": "ap-southeast-2",
    "source_ami": "ami-b7eb9e8d",
    "s3_bucket": "layer2amis",
    "x509_cert_path": "packer/cert-x509.pem",
    "x509_key_path": "packer/key-x509.pem",
    "instance_type": "t2.medium",
    "ssh_username": "ubuntu",
    "ssh_timeout": "5m",
    "ami_virtualization_type": "hvm",
    "ami_name": "layer2_stagingserver_{{timestamp}}",
    "bundle_vol_command": "sudo -n /usr/local/ec2/ec2-ami-tools-1.5.3/bin/ec2-bundle-vol -k {{.KeyPath}} -u {{.AccountId}} -c {{.CertPath}} -r {{.Architecture}} -e {{.PrivatePath}}/* -d {{.Destination}} -p {{.Prefix}} --batch --no-filter",
    "bundle_upload_command": "sudo -n /usr/local/ec2/ec2-ami-tools-1.5.3/bin/ec2-upload-bundle -b {{.BucketName}} -m {{.ManifestPath}} -a {{.AccessKey}} -s {{.SecretKey}} -d {{.BundleDirectory}} --region ap-southeast-2 --batch --retry"
  }],
}

The documentation on the web for packer just says vpc_id (string) - If launching into a VPC subnet, Packer needs the VPC ID in order to create a temporary security group within the VPC.

  • There's an errant space in "vpc_id ". – jzonthemtn Jul 1 '15 at 12:08
6

Exactly as you say, there is a vpc_id option that is pointed out in the documentation of the amazon-ebs builder. You have added this option to your Packer JSON file, however, you added it in the wrong place.

The vpc_id option should be added in your builder object and not in the variables object. So it should look something like this:

{
    "variables": {},
    "builders": [{
        "vpc_id": "vpc-12345678",
        "subnet_id": "subnet-1c5d5c68",
        "type": "amazon-instance",
        "access_key": "somekey",
        "secret_key": "somekey",
        "account_id": "AccountIDNUMBER",

        [...]
    }],
}
| improve this answer | |
  • Hi There, Thanks for the help. Yes I first tried it in the builders section. And it didnt work. I also tried using the subnet_id in the builders section and packer complained and said that these were invalid for this section. I googled around and some people had put them in the Variables section so i tried that, and didnt get an error saying the builders property was incorrect but I still got my VPC error. In the end I had to contact Amazon and get them to re-create my DEFAULT VPC which had been deleted. I am still unable to pack the images in a VPC other than the default VPC. – Daryl B Feb 8 '15 at 7:47
  • You need to specify associate_public_ip_address and subnet_id to make it work on a custom VPC (non-default VPC) – David Roussel Apr 27 '16 at 18:36
  • I never got it to work with vpc_id and subnet_id I /HAD/ to use vpc_filter and subnet_filter – Aaron McMillin Aug 23 '19 at 19:20
1

adding:

    "associate_public_ip_address": "true",
    "ami_virtualization_type": "hvm",

to the manifest worked for me. Here's an example file:

{
  "variables": {
    "aws_access_key": "",
    "aws_secret_key": ""
  },
  "builders": [{
    "type": "amazon-ebs",
    "access_key": "{{user `aws_access_key`}}",
    "secret_key": "{{user `aws_secret_key`}}",
    "region": "eu-west-1",
    "source_ami": "ami-47a23a30",
    "instance_type": "t2.micro",
    "associate_public_ip_address": "true",
    "ami_virtualization_type": "hvm",
    "ssh_username": "ubuntu",
    "ami_name": "packer-exaple {{timestamp}}",
    "ami_description": "An example deployment built with Packer.io",
    "vpc_id": "vpc-XXXXX",
    "subnet_id": "subnet-XXXXX",
    "tags": {"Environment": "test",
             "name": "packer.io test"}
  }]
}
| improve this answer | |
1

You need to add both vpc_id and subnet_id fields in case you dont have default vpc in the account where you are trying to launch the EC2 during the AMI creation. Here is how I have achieved the same.

"variables": {
    "aws_region": "us-west-2",
    "aws_subnet_id": "subnet-xxxxx",
    "aws_vpc_id": "vpc-xxxxx",
    "aws_ami_name": "CentOS-7-HVM-EBS-{{timestamp}}",
}

"builders": [{
    "vpc_id": "{{user `aws_vpc_id`}}",
    "subnet_id": "{{user `aws_subnet_id`}}",
    "type": "amazon-ebs",
    "region": "{{user `aws_region`}}",
    "instance_type": "t2.micro",
    "ssh_username": "centos",
     "ssh_timeout" : "10m",
    "ami_name": "{{user `aws_ami_name`}}",
    "ami_description": "Latest CentOS AMI with EBS backend on HVM",
    "source_ami_filter": {
        "filters": {
             "virtualization-type": "hvm",
              "name": "ops_aws_cent_7_*",
              "root-device-type": "ebs"
                    },
        "owners": ["xxxxxxxxxxx"],
        "most_recent": true
    }
}]
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.