packerhashicorphashicorp-packer

How to avoid packer from assigning public ip to ami


I want to associate an EIP with the ec2 instance that packer creates when we run 'packer build' command. I am setting the "associate_public_ip_address": "false",

and trying to associate EIP by providing 'aws ec2 associate-address --allocation-id' in the 'user_data' of the packer json. Still whenever Packer is creating an ec2 instance for the AMI, its automatically assigning a random public IP. I want to know how to prevent Packer from assigning this random public IP to the ec2 instance.


Solution

  • Subnet auto assign public IP was assigning the IP, irrespective of the above settings. Turning that off from the subnet settings resolved the problem.