After automating the build of a nested vSphere environment, I wanted to test provisioning VMs in vSphere using Terraform.
I’d created a Windows VM with some basic network configuration, sysprep’d it and powered down ready for the single snapshot expected when using Linked-Clones with Terraform.
After taking that single snapshot on the target Windows VM, I created these Terraform configuration files to test cloning: https://github.com/adamrushuk/terraform-vsphere/tree/master/clone-windows-vm
I tried to keep the configuration as basic as possible, but I kept getting the following error:
Error: Error applying plan: 1 error(s) occurred: * vsphere_virtual_machine.vm: 1 error(s) occurred: * vsphere_virtual_machine.vm: Virtual machine customization failed on "/Datacenter/vm/DeployedVMs/winclone04": An error occurred while customizing VM winclone04. For details reference the log file C:/Windows/TEMP/vmware-imc/guestcust.log in the guest OS. The virtual machine has not been deleted to assist with troubleshooting. If corrective steps are taken without modifying the "customize" block of the resource configuration, the resource will need to be tainted before trying again. For more information on how to do this, see the following page: https://www.terraform.io/docs/commands/taint.html Terraform does not automatically rollback in the face of errors. Instead, your Terraform state file has been partially updated with any resources that successfully completed. Please address the error above and apply again to incrementally change your infrastructure.
Looking through the Windows customization log file (
C:/Windows/TEMP/vmware-imc/guestcust.log), I could see things
were taking longer than usual, and the network was not connecting.
It turns out the solution was a simple one.
DONT SYSPREP THE VM!
During the VM clone, vSphere will sysprep the VM for you, so it doesn’t expect the source VM to be sysprep’d already.