Stop using clickops and start automating with Infrastructure as Code concepts. In this video blog post you will learn how to use HashiCorp Packer for VMware to create Ubuntu 18.04 template images in vSphere then use Terraform to deploy these VMs.
Video
Below is a video explanation and demo.
Video Chapters
You can skip to the relevant chapters below:
- 00:00 – Introduction
- 01:32 – Packer Ubuntu Explanation
- 08:28 – vCenter View of Template Created
- 09:31 – Build the VM using Terraform
- 16:31 – vCenter View of VMs Created
- 17:02 – Conclusion
Overview
This video blog post is similar to the one we created for Windows 2019 server images. However, it builds Ubuntu 18.04 images instead.
The two main steps to achieve this are listed below:
- First create a Ubuntu 18.04 template and save it in a templates folder in vCenter using
Packer
. - Then create a VM from this template using
Terraform
.
Code
Pre-requisites
The following is required to follow along:
Setup
Below is our setup diagram.

Troubleshooting Tips
- If packer gets stuck on
Waiting for IP
you may want to check your DHCP server. I’m using a home router and it had too many leases from running packer many times. I had to flush inactive DHCP clients or reboot the router which is faster. - Open the vSphere web console and take a look at the output as the VM is getting created. This can give you some hints as to what is going on.
Conclusion
In this video blog post, we demonstrated two main things:
- How to create a Ubuntu 18.04 machine image in VMware using HashiCorp
Packer
. As you saw, our configuration is all defined in code. There is no need to click around inside the vSphere client to generate this image. We’ve automated the task of building gold machine images in VMware. This makes the process repeatable and self-documented, just a couple of benefits of IaC. - We used
Terraform
to provision the Ubuntu 18.04 VM by cloning thisPacker
generated image.
We also created a post on doing the same for a Ubuntu 20.04 image. Then another post to use this image to Build a Kubernetes k3s Cluster in vSphere with Terraform and Packer.