For a while now I have been struggling with Packer templates built with Ubuntu 20.04 server deployed on VSphere 7.0. When I build the packer image and deploy VM’s with terraform specifying a static IP with terraforms customize block, DHCP would pick up an additional IP address as well as the static IP.
I found that the issue stemmed from packer requiring dhcp assignment for the post deploy ssh shell provisioner. To solve this issue a few lines of code were added to the provisioner to:
- Remove netplan config
- Remove dhcp from grub file
- Update grub
- Purge cloud-init
I have included the .hcl code below, after building this template, all terraform provisioned vm’s off this template will only have the static IPs assigned via the customize block.
I have also include a sample main.tf below:
I hope this quick write up help anyone with this issue. It took me quite a bit of researching and was unable to find a single solution. I wished that a resource such as this one was available so I decided to make it.