Using Terraform for Fast, Immutable VMs
Terraform is an excellent tool tool. It allows users to quickly provision and configure a vast range of infrastructure. For this article, we’ll be using Terraform to provision a Ubuntu virtual machine in VMWare Vsphere. In order to do this, there must be a pre-configured VM template in Vsphere that can be used to create VMs from. To do this I created a minimal Ubuntu VM with the following attributes:
- 1 vCPUs
- 1 GB RAM
- 16 GB hdd thin-provisioned
- Dynamic IP v4 settings
- Hostname: tpl-ubuntu18
This was enough to install a minimal Ubuntu 18.04 OS. The only package I added was the optional OpenSSH server to I could access the VM outside the VMWare console.
I also added an SSH public key so I could shell in without supplying a password. Besides being convenient, it is also necessary for Ansible to connect to any VMs cloned from the template later.
There is a bug with the open-vm-tools package for Ubuntu 18.04 that prevents guest customization from working correctly. To resolve this issue as described in this VMWare KB article ( https://kb.vmware.com/s/article/56409 ), I commented out a line in /usr/lib/tmpfiles.d/tmp.conf and added another in /lib/systemd/system/open-vm-tools.service.

After running updates, I converted the VM to a template:

Great content! Keep up the good work!