Are you still creating vSphere images by clicking in the UI? Are you doing the same to deploy these images in vSphere? You really should stop and consider automating the process with Infrastructure as Code using Packer and Terraform. Learn how to do this in this video blog post.
Video
Below is a video explanation and demo.
Video Chapters
You can skip to the relevant chapters below:
- 00:00 – Introduction
- 01:42 – Packer Windows Explanation
- 06:56 – vCenter View of Template Created
- 07:29 – Build the VM using Terraform
- 11:56 – vCenter View of VMs Created
- 12:37 – Conclusion
Overview
We continue to see an increased interest in using Infrastructure as Code tools such as Packer
and Terraform
in on-premises environments running vSphere. In this video blog post, we will explore this with the help of a video demo. There are two main steps here:
- First create a Windows Server 2019 template using 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 Windows Server 2019 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 images in VMware. This makes the process repeatable and self-documented, just a couple of benefits of IaC. - We used
Terraform
to provision the Windows 2019 server 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.
Good tutorial – my template build is failing as WinRM never returns a successful connection and hangs on:
==> vsphere-iso: Waiting for WinRM to become available…
VMware tools is installed, the VM has acquired an IP address and is remotely accessible.
Any thoughts?
A few things to check:
1. Check network connectivity: Ensure that the VM has proper network connectivity and can communicate with the machine running the build process. Make sure the firewall settings allow WinRM connections.
2. Verify WinRM configuration: Double-check the configuration of WinRM on the VM. Ensure that WinRM is enabled and configured correctly to allow remote connections. You can use the winrm get winrm/config command on the VM to check the current configuration.
3. Check WinRM service: Ensure that the WinRM service is running on the VM. You can check the service status using the Get-Service winrm command in PowerShell.
4. Validate VMware Tools: Although you mentioned that VMware Tools is installed, it’s worth ensuring that it is functioning correctly. Restart the VMware Tools service on the VM and verify that it is running properly.
5. Increase WinRM timeout: If the default timeout value for the WinRM connection is too short, it could lead to timeouts and connection failures. You can try increasing the WinRM timeout value in your template or script to give it more time to establish a connection.