How to deploy Ubuntu 20.04 packer templates for terraform on VSphere without duplicate IP’s

Background

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:

  1. Remove netplan config
  2. Remove dhcp from grub file
  3. Update grub
  4. Purge cloud-init

Code

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.

Related Posts

Terraform Tips & Tricks – Part 1 – Building A Constant Reference

One of the most common problems I see in large organizations when working with terraform is consistency. When we have a large amount of resources being managed…

Everything You Ever Wanted to Know About Istio but Were Afraid to Ask

Istio is a powerful service mesh that integrates natively with Kubernetes, I have been using Istio as my service mesh, ingress, and egress gateways on my personal…

How to Monitor Your Enphase Home Solar System with Telegraf

How to collect metrics from an Enphase Envoy PV system, with telegraf and influxdb.

How to Deploy Anthos on Bare Metal On-Prem

Introduction The main advantage of Anthos on BM over Anthos on VMWare for on-prem deployments is the ability to run Anthos clusters without a hypervisor license. Cluster…

OPA Gatekeeper: Bringing Law and Order to Kubernetes

Introduction Open Policy Agent (OPA) is a policy based control agent that is able to be integrated on various platforms. For the sake of this document we…

How to Setup Anthos on GKE Autopilot with Private Certificate Authority

What You Will Create The guide will set up the following: 2 Private GKE autopilot clusters with master global access ASM with multicluster mesh IstioIngress gateway to…

Leave a ReplyCancel reply

Exit mobile version