terraform-provider-vsphere: Customization does not work for windows 2008 R2 template

Terraform Version

v0.10.1

Affected Resource(s)

  • terraform-provider-vsphere

Terraform Configuration Files

resource "vsphere_virtual_machine" "TerraformSampleMachine" {

    count = "${length(var.vms_address)}"

    datacenter = "${var.datacenter}"
    resource_pool = "${var.resource_pool}"

    name = "${element(var.vms_name, count.index)}"
    dns_suffixes = "${var.dns_suffixes}"
    dns_servers  = "${var.dns_servers}"
    vcpu = "${element(var.vms_vcpu, count.index)}"
    memory = "${element(var.vms_memory, count.index)}"


    network_interface {
        label = "VM Network"
        ipv4_prefix_length = "22"
        ipv4_address = "${element(var.vms_address, count.index)}"
        ipv4_gateway = "${element(var.vms_gateway, count.index)}"
    }

    disk {
        datastore = "${var.datastore}"
        template = "${var.templates["windows_2008_R2"]}"
        type = "thin"
    }
}

Debug Output

https://gist.github.com/Rocking80/e9f55a5b5403ca1a629c798ed9e1b5fb

Expected Behavior

The windows 2008 R2 machine should be created and configured correctly. And terraform apply finish successfully.

Actual Behavior

The windows 2008 R2 machine is created but network for it (ip, gateway, DNS) and hostname is not configured. And terraform apply is always printing ‘Still creating’ without ending.

Steps to Reproduce

  1. terraform apply

Important Factoids

From the vcenter console, we can see the vmware tasks are done without error. tasks are:

  1. clone virtual machine
  2. Reconfigure virtual machine
  3. Reconfigure virtual machine
  4. Customize virtual machine guest OS
  5. Power on virtual machine

After all tasks are finished and wait for half an hour, I am trying to logon to the machine, there is message prompt to restart the machine. I restarted the machine manually and still does not work.

The vmware tools are latest on the template machine.

Windows 2012 R2 does work.

Don’t know if this is a terraform issue or a vmware API issue?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 17 (4 by maintainers)

Commits related to this issue

Most upvoted comments

Hey all!

As the issue log here indicates, I’ve made some significant changes here that should fix this issue now:

  • Customization events are now the source of truth for customization completion, ensuring that a VM is not “created” until this part is fully reported as complete.
  • The behaviour of the network waiter has been significantly changed - we now wait for a routeable address, it’s no longer run on Read, but Create and Update instead, and can actually be completely disabled (if you have a config with NICs without a default route or no configuration at all).

The latter was needed as on my own config, after fixing the customization, there’s a small moment after customization completes that VMware tools reports an auto-configuration address (169.254.x.x) before changing to the proper static configuration. This gets passed to the provisioner which obviously causes the provisioner to fail.

Anyway, we are bumping to 0.3.0 and will releasing shortly, so keep an eye out!

Hey all! Sorry for the silence on this one, just wanted to make sure that I was able to take the time to give this one some attention.

So it looks like we definitely have an issue here. It probably stems from this:

2017-09-11T09:05:47.620-0700 [DEBUG] plugin.terraform-provider-vsphere_v0.2.2_x4: 2017/09/11 09:05:47 [DEBUG] VM customization starting
2017-09-11T09:05:50.573-0700 [DEBUG] plugin.terraform-provider-vsphere_v0.2.2_x4: 2017/09/11 09:05:50 [DEBUG] VM customization finished

That is the CustomizeVM call on a W2K16 template taking 3 seconds to return success. 😕

Obviously, this is taking much longer than three seconds - about a couple of minutes for my test VM.

Looking into it, and obviously from what we’ve seen here, this is not a accurate way to wait for customization to complete. I have done a bit of research into it, and it looks like the correct way to do this is to watch for customization events, which can clearly be seen in the event log in vCenter.

govmomi has an events package that I’d imagine encapsulates the events part of the API. I don’t know if there’s a waiter, but TF itself has an API that we can use to wait for the event anyway, so that’s not a big deal.

I think this is an easy win for us to make the VM resource better to work with without having to wait for the refactor (in addition, we will need this for the refactor anyway) so I will be prioritizing this one.

Cheers!