terraform-provider-vsphere: NIC not connected when cloning VM from template

Terraform Version

Terraform v0.11.3

vSphere Provider Version

provider.vsphere v1.3.0

Affected Resource(s)

  • vsphere_virtual_machine

Terraform Configuration Files

provider "vsphere" {
  user           = "${var.vsphere_user}"
  password       = "${var.vsphere_password}"
  vsphere_server = "${var.vsphere_server}"

  # if you have a self-signed cert
  allow_unverified_ssl = true
}

data "vsphere_datacenter" "dc" {
  name = "Datacenter"
}

data "vsphere_datastore" "datastore" {
  name          = "STAGING"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

data "vsphere_resource_pool" "pool" {
  name          = "CLUS01/Resources"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

data "vsphere_network" "network" {
  name          = "DVOPS"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

data "vsphere_virtual_machine" "template" {
  name          = "20180130 - Server 2012R2 Datacenter"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

resource "vsphere_virtual_machine" "vm" {
  name             = "terraform-test"
  resource_pool_id = "${data.vsphere_resource_pool.pool.id}"
  datastore_id     = "${data.vsphere_datastore.datastore.id}"
  folder = "DVOPS1690"

  num_cpus = 1
  memory   = 2048
  guest_id = "${data.vsphere_virtual_machine.template.guest_id}"

  scsi_type = "${data.vsphere_virtual_machine.template.scsi_type}"

  network_interface {
    network_id   = "${data.vsphere_network.network.id}"
  }

  disk {
    label            = "disk0"
    size             = "${data.vsphere_virtual_machine.template.disks.0.size}"
    eagerly_scrub    = "${data.vsphere_virtual_machine.template.disks.0.eagerly_scrub}"
    thin_provisioned = "${data.vsphere_virtual_machine.template.disks.0.thin_provisioned}"
  }
  disk {
    label            = "disk1"
    size             = "${data.vsphere_virtual_machine.template.disks.1.size}"
    eagerly_scrub    = "${data.vsphere_virtual_machine.template.disks.1.eagerly_scrub}"
    thin_provisioned = "${data.vsphere_virtual_machine.template.disks.1.thin_provisioned}"
    unit_number = 1
  }
  clone {
    template_uuid = "${data.vsphere_virtual_machine.template.id}"
      
    customize {
        windows_options {
        computer_name  = "terraform-test"
      }
      network_interface {
        ipv4_address = "172.20.90.125"
        ipv4_netmask = 27
        dns_server_list = ["${var.virtual_machine_dns_servers}"]
        
      }

      ipv4_gateway = "172.20.90.97"
    }
  }
}


variable "vsphere_server" {
    description = "vsphere server for the environment - EXAMPLE: vcenter01.hosted.local"
    default = "vcenter01.hosted.local"
}

variable "vsphere_user" {
    description = "vsphere server for the environment - EXAMPLE: vsphereuser"
    default = "vsphereuser"
}

variable "vsphere_password" {
    description = "vsphere server password for the environment"
    default = "vspherep@ssw0rd"
}

variable "virtual_machine_dns_servers" {
  type    = "list"
  default = ["8.8.8.8", "4.2.2.2"]
}

Debug Output

Debug Output: https://gist.github.com/ronmessana-concerto/c91829184833ccad7991e3665f6cda95

Panic Output

n/a

Expected Behavior

What should have happened? When cloning a VM from a template, the network adapter has the “connected” and “connect at power on” boxes checked.

Actual Behavior

What actually happened? When cloning a VM from a template, the network adapter does not have the “connected” or “connect at power on” boxes checked, leading to failures in configurtion

Steps to Reproduce

  1. run ‘terraform apply’ using the above configuration.

Important Factoids

-VMWare vCenter server 6.0.0 Build 5218300 -When creating a VM from scratch, not using a template, the NIC is always connected.

  • Issue exists on both Windows and Linux terraform builds

References

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 31 (6 by maintainers)

Most upvoted comments

I was having the same issue where my nic was showing up disconnected when I had a customize config. I dug a bit and found the following error in /var/log/vmware-imc/toolsDeployPkg.log: Customization command failed: Failed to create bus connection: No such file or directory

I fixed this by adding After=dbus.service in my /lib/systemd/system/open-vm-tools.service and then re-cloning the template.

Re-running my terraform code with that updated template successfully fixed my error.

I too am experiencing the same issues.

I’ve tried different versions of the vSphere provider to no avail. Running vSphere 6.7.0.

If cloning from a Windows Template using customize the NIC doesn’t appear to be connected. Sure, the customize may be failing.

In my case the customize is naming the machine and joining a domain - which works perfectly fine when running it via vSphere directly.

customize {
   network_interface = {}
   windows_options {
      computer_name = "${var.hostname}"
      join_domain = "${var.domain}"
      domain_admin_user = "${var.domainuser}"
      domain_admin_password = "${var.domainuserpw}"
      admin_password = "${var.secretpw}"
   }
}

From the cusomization logs

[2018-09-27T15:22:38:                              :  DEBUG] Temporary sysprep dir path: C:\sysprep
[2018-09-27T15:22:38:                              :  DEBUG] Copying file/directory from 'sysprep' to 'C:\sysprep'
[2018-09-27T15:22:39:                              :   INFO] Sysprep File is C:\Windows\Panther\unattend.xml
[2018-09-27T15:22:39:                              :   INFO] Password unobfuscation in progress
[2018-09-27T15:22:39:                              :  DEBUG] Decrypting passwords
[2018-09-27T15:22:39:                              :  DEBUG] Password found and decrypted for <AdministratorPassword><EncryptedValue>
[2018-09-27T15:22:39:                              :  DEBUG] Password found and decrypted for <Credentials><EncryptedPassword>
[2018-09-27T15:22:39:                              :  DEBUG] Tag <Value> not found after <Password>
[2018-09-27T15:22:39:                              :  DEBUG] Tag  -de  not found after <RunSynchronousCommand
[2018-09-27T15:22:39:                              :   INFO] Password unobfuscation successful
[2018-09-27T15:22:39:                              :  DEBUG] select * from win32_networkadapter where Manufacturer != 'Microsoft' and ServiceName != 'VMnetAdapter' and  manufacturer is not null and MACAddress is not null
[2018-09-27T15:22:39:                              :  DEBUG] Found 0 objects. Pointer 0. return code -2147217398(0x8004100a)
[2018-09-27T15:22:39:                              :  ERROR] WinMgmt : 
[2018-09-27T15:22:39:                              :  DEBUG] HandleCustomizationFailed
[2018-09-27T15:22:39:                              :  DEBUG] Customization in progress set to 0 at 2018-Sep-27 15:22:39
[2018-09-27T15:22:39:                              :   INFO] Cleaning up obfuscation details from registry
[2018-09-27T15:22:39:                 GuestCustUtil:  DEBUG] Status marker file C:/Windows/.post-gc-status doesn't exist
[2018-09-27T15:22:39:                              :  DEBUG] GOScPostRebootStatus feature is enabled
[2018-09-27T15:22:39:                 GuestCustUtil:  DEBUG] SetVmxProperty: key-'guestinfo.gc.notification', value-'WinMgmt : '
[2018-09-27T15:22:39:     WindowsOsAbstractionLayer:   INFO] VMware tools installation path=C:\Program Files\VMware\VMware Tools\
[2018-09-27T15:22:39:     WindowsOsAbstractionLayer:   INFO] Executing command: '"C:\Program Files\VMware\VMware Tools\vmtoolsd.exe" --cmd "info-set guestinfo.gc.notification WinMgmt : "'
[2018-09-27T15:22:39:     WindowsOsAbstractionLayer:   INFO] Command execution succeeded, output: '

The same issue has been reported here https://stackoverflow.com/questions/50482281/vspehere-vs-terraform-vm-customization-failure-with-network-not-being-connected

Update After spending a little time playing around. I figured out that the Template that I’d been provided had already been sysprep’d. After converting to a VM, starting, logging in, shutting down and converting it back to a template this appeared to fix any issues with customizations/NIC being enabled/disabled at correct times.

Hey @emdantrim! I don’t know if the problem would be with the OVA per se - as far as it’s concerned, it’s running “just fine” in that if you use it “as intended” (ie: configure through cloud-config/user data), then you’ll be fine (as long as you can deal with the DHCP delay).

Unless you can find anything specific in the customization logs that would indicate a specific issue with the image that’s causing customization to not work, then they might not do much about it 😕

What I would probably do: If you prefer customization over cloud-config (and with the Ubuntu OVA, I definitely wouldn’t blame you 🙂), maybe just manually seed a template from a ISO install. This is what we do for our tests - you sidestep all of the weird config the OVA has with default DHCP and the serial console redirect, and cloud-init is not on the server when it’s not necessarily needed. You can set the interfaces to a dummy static IP address and the boot-up/customization phase will take about 30 seconds or so.

Otherwise, if you are looking for an OVA that works really well with VMware and the vSphere provider, the best one I’ve found so far is the CoreOS OVA. You can configure the VM entirely from Ignition and pass that into the guestinfo.coreos.config.data property, and even generate it with the Ignition provider.

Hope this helps!

I’m running into this issue with Centos 7.7, I’m simply trying to set a hostname and bring up a interface. What is odd is that once you customize, you need to provide a interface, whereas if you leave customization empty the nic comes up fine.

clone { template_uuid = “${data.vsphere_virtual_machine.template.id}” customize { linux_options { host_name = “vm-one” domain = “example.com” } network_interface { }

}

}

Terraform Error: Error: Virtual machine customization failed on “/Lab/vm/TestC7”:

timeout waiting for customization to complete

What is the workaround?

Terraform 0.12.12 provider.vsphere: version = “~> 1.13” Centos 7.7 Vsphere 6.7

Guys has it been fixed to any new version or do we still need to manually turn the interface on?

I have used the settings -

wait_for_guest_net_timeout = 0 wait_for_guest_net_routable = false

This is the error i get for sysprepd machine -

[2018-10-25T02:50:16: : DEBUG] Copying file/directory from ‘sysprep’ to ‘C:\sysprep’ [2018-10-25T02:50:16: : DEBUG] select * from win32_networkadapter where Manufacturer != ‘Microsoft’ and ServiceName != ‘VMnetAdapter’ and manufacturer is not null and MACAddress is not null [2018-10-25T02:50:16: : DEBUG] Found 0 objects. Pointer 0. return code -2147217398(0x8004100a) [2018-10-25T02:50:16: : DEBUG] Rpci: Sending request='deployPkg.update.state 4 101 C:/Windows/TEMP/vmware-imc/guestcust.log@WinMgmt : ’

[2018-10-25T02:50:16: : DEBUG] Rpci: Sent request=‘deployPkg.update.state 4 101 C:/Windows/TEMP/vmware-imc/guestcust.log@WinMgmt : ‘, reply=’’, len=0, status=1

[2018-10-25T02:50:16: GuestCustUtil: DEBUG] Status marker file C:/Windows/.post-gc-status doesn’t exist [2018-10-25T02:50:16: : ERROR] error number 8004100a, WinMgmt : [2018-10-25T02:50:16: : INFO] GuestCustUtil exiting.

I’m facing this issue which is restricting me to do more automation. Has there been any fix on this? My cloned VM customization fails due to errors and if i check, the VM has its network interface disconnected.