Search code examples
amazon-web-servicesamazon-ec2amazon-amipacker

Packer build with private ip


I am using Packer to bake an AMI. It works fine by assigning public ip and temporary security group, but I do not want to assign public ip to temporary instance is there a way to prevent it assigning public ip?

data "amazon-ami" "ami_id" {
  filters = {
    virtualization-type = "hvm"
    name                = "APP-Linux-Centos-*"
    root-device-type    = "ebs"
  }
  owners      = ["11223321"]
  most_recent = true
  region      = "us-east-1"
}

source "amazon-ebs" "instance" {
  region      = "us-east-1"
  ssh_username  = "ec2-user"
  ami_name      = "test12-${uuidv4()}"
  source_ami    = "ami-0#####06"
  instance_type = "t2.micro"
  vpc_id = "vpc-q#####f "
  subnet_id = "subnet-q######d"
  associate_public_ip_address = false
  security_group_ids =["sg-3#####6","sg-f####f"]
}
build {
  sources = ["amazon-ebs.instance"]
}

here i am using

associate_public_ip_address = false

but still i see public ip is attached while running packer build is there a way to prevent instance from getting assigned with public ip ?


Solution

  • If you are using a non-default VPC, then the associate_public_ip_address isn't sufficient (it's false by default anyway). To build over a private ip, you also need to use:

    ssh_interface = "private_ip"