title: vSphere vs. terraform VM Customization Failure with Network not being connected
body: <p>When I'm trying to customize the network interface post provision of a Windows VM, terraform errors, VM is left running with no NIC attached.</p>
  <p><strong>Version</strong><br />
  Terraform = v0.11.7<br />
  vSphere Version = 6.7.0, 8169922<br />
  Machine clone of Windows 2012 R2</p>
  <p><strong>Investigation so far;</strong><br />
  Within vCenter and the VM settings the &quot;Network Adapter 1&quot; is not marked to start on power up. It's as if during the customization that this setting is lost which is resulting in lack of comms to the VM.  If I power the server off then check the box to connect NIC on start up then when the server comes back online it has its network configuration correct as defined in the customization section. I have also stripped back the customization to bare minimum and still get the same fault.</p>
  <p><strong>terraform console output</strong></p>
  <pre><code>Error dumps below.
  
      Error: Error applying plan:
      
      
      1 error(s) occurred:
      
      
      * vsphere_virtual_machine.Clone: 1 error(s) occurred:
      
      
      * vsphere_virtual_machine.Clone:
      Virtual machine customization failed on &quot;/Data Center/vm/AIS1EM-SAMSON&quot;:
      
      
      An error occurred while customizing VM AIS1EM-SAMSON. For details reference the log file C:/Windows/TEMP/vmware-imc/guestcust.log in the guest OS.
  </code></pre>
  <p><strong>Customfile log from VM</strong></p>
  <pre><code>[2018-05-22T17:35:13:                              :   INFO] GuestCustUtil invoked.
  [2018-05-22T17:35:13:                              :   INFO] Params: customize -sealparam &quot;/quiet /generalize /oobe /reboot&quot; -nics 4000 -schedulenativeunobfusc
  [2018-05-22T17:35:13:                              :  DEBUG] Registry value 'CustomRescheduleFlags' is not set. Returning default value: 0
  [2018-05-22T17:35:13:                              :   INFO] Checking for Windows Sysprep Respecialize operation.
  [2018-05-22T17:35:13:                              :  DEBUG] Sysprep process is not running.
  [2018-05-22T17:35:13:                              :   INFO] Windows Sysprep Respecialize operation was not detected.
  [2018-05-22T17:35:13:                 GuestCustUtil:  DEBUG] Deleting status marker file C:/Windows/.post-gc-status
  [2018-05-22T17:35:13:                 GuestCustUtil:  DEBUG] Status marker file C:/Windows/.post-gc-status doesn't exist
  [2018-05-22T17:35:13:                              :   INFO] Extended customization is not enabled!
  [2018-05-22T17:35:13:                              :  DEBUG] HandleCustomizationStarted
  [2018-05-22T17:35:13:                              :  DEBUG] Customization in progress set to 1 at 2018-May-22 17:35:13
  [2018-05-22T17:35:13:                              :  DEBUG] GOScPostRebootStatus feature is enabled
  [2018-05-22T17:35:13:                 GuestCustUtil:  DEBUG] SetVmxProperty: key-'guestinfo.gc.notification', value-'Started'
  [2018-05-22T17:35:13:     WindowsOsAbstractionLayer:   INFO] VMware tools installation path=C:\Program Files\VMware\VMware Tools\
  [2018-05-22T17:35:13:     WindowsOsAbstractionLayer:   INFO] Executing command: '&quot;C:\Program Files\VMware\VMware Tools\vmtoolsd.exe&quot; --cmd &quot;info-set guestinfo.gc.notification Started&quot;'
  [2018-05-22T17:35:13:     WindowsOsAbstractionLayer:   INFO] Command execution succeeded, output: '
  
  '
  [2018-05-22T17:35:13:                              :  DEBUG] Rpci: Sending request='deployPkg.update.state 4 0 C:/Windows/TEMP/vmware-imc/guestcust.log'
  
  [2018-05-22T17:35:13:                              :  DEBUG] Rpci: Sent request='deployPkg.update.state 4 0 C:/Windows/TEMP/vmware-imc/guestcust.log', reply='', len=0, status=1
  
  [2018-05-22T17:35:13:                              :  DEBUG] Temporary sysprep dir path: C:\sysprep
  [2018-05-22T17:35:13:                              :  DEBUG] Copying file/directory from 'sysprep' to 'C:\sysprep'
  [2018-05-22T17:35:13:                              :   INFO] Sysprep File is C:\Windows\Panther\unattend.xml
  [2018-05-22T17:35:13:                              :   INFO] Password unobfuscation in progress
  [2018-05-22T17:35:13:                              :  DEBUG] Decrypting passwords
  [2018-05-22T17:35:13:                              :  DEBUG] Password found and decrypted for &lt;AdministratorPassword&gt;&lt;EncryptedValue&gt;
  [2018-05-22T17:35:13:                              :  DEBUG] preTag &lt;Credentials&gt; not found
  [2018-05-22T17:35:13:                              :  DEBUG] preTag &lt;Password&gt; not found
  [2018-05-22T17:35:13:                              :  DEBUG] Tag  -de  not found after &lt;RunSynchronousCommand
  [2018-05-22T17:35:13:                              :   INFO] Password unobfuscation successful
  [2018-05-22T17:35:14:                              :  DEBUG] select * from win32_networkadapter where Manufacturer != 'Microsoft' and ServiceName != 'VMnetAdapter' and  manufacturer is not null and MACAddress is not null
  [2018-05-22T17:35:14:                              :  DEBUG] Found 0 objects. Pointer 0. return code -2147217398(0x8004100a)
  [2018-05-22T17:35:14:                              :  ERROR] WinMgmt : 
  [2018-05-22T17:35:14:                              :  DEBUG] HandleCustomizationFailed
  [2018-05-22T17:35:14:                              :  DEBUG] Customization in progress set to 0 at 2018-May-22 17:35:14
  [2018-05-22T17:35:14:                              :   INFO] Cleaning up obfuscation details from registry
  [2018-05-22T17:35:14:                 GuestCustUtil:  DEBUG] Status marker file C:/Windows/.post-gc-status doesn't exist
  [2018-05-22T17:35:14:                              :  DEBUG] GOScPostRebootStatus feature is enabled
  [2018-05-22T17:35:14:                 GuestCustUtil:  DEBUG] SetVmxProperty: key-'guestinfo.gc.notification', value-'WinMgmt : '
  [2018-05-22T17:35:14:     WindowsOsAbstractionLayer:   INFO] VMware tools installation path=C:\Program Files\VMware\VMware Tools\
  [2018-05-22T17:35:14:     WindowsOsAbstractionLayer:   INFO] Executing command: '&quot;C:\Program Files\VMware\VMware Tools\vmtoolsd.exe&quot; --cmd &quot;info-set guestinfo.gc.notification WinMgmt : &quot;'
  [2018-05-22T17:35:14:     WindowsOsAbstractionLayer:   INFO] Command execution succeeded, output: '
  
  '
  [2018-05-22T17:35:14:                              :  DEBUG] Rpci: Sending request='deployPkg.update.state 4 100 C:/Windows/TEMP/vmware-imc/guestcust.log@WinMgmt : '
  
  [2018-05-22T17:35:14:                              :  DEBUG] Rpci: Sent request='deployPkg.update.state 4 100 C:/Windows/TEMP/vmware-imc/guestcust.log@WinMgmt : ', reply='', len=0, status=1
  
  [2018-05-22T17:35:14:                              :   INFO] GuestCustUtil exiting.
  
  [2018-05-22T17:35:23:                              :   INFO] GuestCustUtil invoked.
  [2018-05-22T17:35:23:                              :   INFO] Params: restoreMountedDevices 
  [2018-05-22T17:35:23:                              :  DEBUG] Registry value 'CustomRescheduleFlags' is not set. Returning default value: 0
  [2018-05-22T17:35:23:                              :   INFO] Checking for Windows Sysprep Respecialize operation.
  [2018-05-22T17:35:23:                              :  DEBUG] Sysprep process is not running.
  [2018-05-22T17:35:23:                              :   INFO] Windows Sysprep Respecialize operation was not detected.
  [2018-05-22T17:35:23: SysprepDriveLettersWorkaround:  DEBUG] Restoring HKLM MountedDevices to fix sysprep issue
  [2018-05-22T17:35:23:                              :  DEBUG] Enabling SE_RESTORE_NAME privilege
  [2018-05-22T17:35:23:                              :  DEBUG] Retrieving process access token for SeRestorePrivilege
  [2018-05-22T17:35:23:                              :  DEBUG] Getting LUID
  [2018-05-22T17:35:23:                              :  DEBUG] Adjusting privileges
  [2018-05-22T17:35:23:                              :  DEBUG] Restoring SYSTEM\MountedDevices from C:\sysprep\MountedDevicesBackup
  [2018-05-22T17:35:23: SysprepDriveLettersWorkaround:   WARN] Failed to restore MountedDevices: The system cannot find the file specified.
  
  . Ignoring
  [2018-05-22T17:35:23:                              :   INFO] GuestCustUtil exiting.
  
  [2018-05-22T17:35:23:                              :   INFO] GuestCustUtil invoked.
  [2018-05-22T17:35:23:                              :   INFO] Params: flagComplete 
  [2018-05-22T17:35:23:                              :  DEBUG] Registry value 'CustomRescheduleFlags' is not set. Returning default value: 0
  [2018-05-22T17:35:23:                              :   INFO] Checking for Windows Sysprep Respecialize operation.
  [2018-05-22T17:35:23:                              :  DEBUG] Sysprep process is not running.
  [2018-05-22T17:35:23:                              :   INFO] Windows Sysprep Respecialize operation was not detected.
  [2018-05-22T17:35:23:                 GuestCustUtil:  DEBUG] Status marker file C:/Windows/.post-gc-status doesn't exist
  [2018-05-22T17:35:23:     WindowsOsAbstractionLayer:   INFO] Executing command: 'C:\Windows\system32\schtasks.exe /query /tn &quot;VMware Guest OS Customization Task&quot;'
  [2018-05-22T17:35:23:     WindowsOsAbstractionLayer:   WARN] Command execution failed with exit code: 1, output: 'ERROR: The system cannot find the file specified.
  
  
  '
  [2018-05-22T17:35:23:                 GuestCustUtil:  DEBUG] SchedulePostCustomizationActivity: Run Command-'HandleCustomizationCompleted&lt;\|/&gt;'
  [2018-05-22T17:35:23:                 GuestCustUtil:   INFO] Scheduling post-customization activity to run after reboot...
  [2018-05-22T17:35:23:     WindowsOsAbstractionLayer:   INFO] Executing command: 'C:\Windows\system32\schtasks.exe /query /tn &quot;VMware Guest OS Customization Task&quot;'
  [2018-05-22T17:35:23:     WindowsOsAbstractionLayer:   WARN] Command execution failed with exit code: 1, output: 'ERROR: The system cannot find the file specified.
  
  
  '
  [2018-05-22T17:35:23:                 GuestCustUtil:   INFO] Task 'VMware Guest OS Customization Task' exists and will be deleted: false
  [2018-05-22T17:35:23:                 GuestCustUtil:  DEBUG] Artifact full path: C:\sysprep\libeay32.dll
  [2018-05-22T17:35:23:                 GuestCustUtil:   INFO] Copying C:\sysprep\libeay32.dll to C:\Windows\TEMP\vmw857B.tmp.
  [2018-05-22T17:35:23:                              :  DEBUG] Copying file/directory from 'C:\sysprep\libeay32.dll' to 'C:\Windows\TEMP\vmw857B.tmp'
  [2018-05-22T17:35:23:                 GuestCustUtil:  DEBUG] Artifact full path: C:\sysprep\ssleay32.dll
  [2018-05-22T17:35:23:                 GuestCustUtil:   INFO] Copying C:\sysprep\ssleay32.dll to C:\Windows\TEMP\vmw857B.tmp.
  [2018-05-22T17:35:23:                              :  DEBUG] Copying file/directory from 'C:\sysprep\ssleay32.dll' to 'C:\Windows\TEMP\vmw857B.tmp'
  [2018-05-22T17:35:23:                 GuestCustUtil:  DEBUG] Artifact full path: C:\sysprep\guestcustutil.exe
  [2018-05-22T17:35:23:                 GuestCustUtil:   INFO] Copying C:\sysprep\guestcustutil.exe to C:\Windows\TEMP\vmw857B.tmp.
  [2018-05-22T17:35:23:                              :  DEBUG] Copying file/directory from 'C:\sysprep\guestcustutil.exe' to 'C:\Windows\TEMP\vmw857B.tmp'
  [2018-05-22T17:35:23:                 GuestCustUtil:  DEBUG] Schedule command: 'C:\Windows\TEMP\vmw857B.tmp\guestcustutil.exe post-run HandleCustomizationCompleted&lt;\|/&gt;'
  [2018-05-22T17:35:23:                              :   INFO] Scheduling 'VMware Guest OS Customization Task'
  [2018-05-22T17:35:23:                              :  DEBUG] Executing command C:\Windows\system32\schtasks.exe /create /sc ONSTART /rl HIGHEST /np /z /v1 /ru SYSTEM /tr &quot;C:\Windows\TEMP\vmw857B.tmp\guestcustutil.exe post-run HandleCustomizationCompleted&lt;\|/&gt;&quot; /tn &quot;VMware Guest OS Customization Task&quot;
  [2018-05-22T17:35:23:                 GuestCustUtil:   INFO] Post-customization activity successfully scheduled.
  [2018-05-22T17:35:23:                              :   INFO] GuestCustUtil exiting.
  
  [2018-05-22T17:35:23:                              :   INFO] GuestCustUtil invoked.
  [2018-05-22T17:35:23:                              :   INFO] Params: deleteContainingFolder 
  [2018-05-22T17:35:23:                              :  DEBUG] Registry value 'CustomRescheduleFlags' is not set. Returning default value: 0
  [2018-05-22T17:35:23:                              :   INFO] Checking for Windows Sysprep Respecialize operation.
  [2018-05-22T17:35:23:                              :  DEBUG] Sysprep process is not running.
  [2018-05-22T17:35:23:                              :   INFO] Windows Sysprep Respecialize operation was not detected.
  [2018-05-22T17:35:23:                              :  DEBUG] Deleting &quot;C:\sysprep&quot; ...
  [2018-05-22T17:35:23:                              :  DEBUG] Deleted folder &quot;C:\sysprep&quot; .
  [2018-05-22T17:35:23:                              :   INFO] GuestCustUtil exiting.
  
  [2018-05-22T17:35:47:                              :   INFO] GuestCustUtil invoked.
  [2018-05-22T17:35:47:                              :   INFO] Params: post-run HandleCustomizationCompleted&lt;\|/&gt;
  [2018-05-22T17:35:47:                              :  DEBUG] Registry value 'CustomRescheduleFlags' is not set. Returning default value: 0
  [2018-05-22T17:35:47:                              :   INFO] Checking for Windows Sysprep Respecialize operation.
  [2018-05-22T17:35:47:                              :  DEBUG] Sysprep process is not running.
  [2018-05-22T17:35:47:                              :   INFO] Windows Sysprep Respecialize operation was not detected.
  [2018-05-22T17:35:47:                              :   INFO] Post-customization run operation: script 'HandleCustomizationCompleted&lt;\|/&gt;'
  [2018-05-22T17:35:47:                              :   INFO] post-run HandleCustomizationCompleted
  [2018-05-22T17:35:47:                              :   INFO] Deleting post-customization task to avoid re-execution
  [2018-05-22T17:35:47:     WindowsOsAbstractionLayer:   INFO] Executing command: 'C:\Windows\system32\schtasks.exe /query /tn &quot;VMware Guest OS Customization Task&quot;'
  [2018-05-22T17:35:48:     WindowsOsAbstractionLayer:   INFO] Command execution succeeded, output: '
  
  Folder: \
  
  TaskName                                 Next Run Time          Status         
  
  ======================================== ====================== ===============
  
  VMware Guest OS Customization Task       N/A                    Running        
  
  '
  [2018-05-22T17:35:48:                 GuestCustUtil:   INFO] Task 'VMware Guest OS Customization Task' exists and will be deleted: true
  [2018-05-22T17:35:48:                              :   INFO] Deleting 'VMware Guest OS Customization Task'
  [2018-05-22T17:35:48:                              :  DEBUG] Executing command C:\Windows\system32\schtasks.exe /delete /f /tn &quot;VMware Guest OS Customization Task&quot;
  [2018-05-22T17:35:48:                              :  DEBUG] HandleCustomizationCompleted
  [2018-05-22T17:35:48:                              :  DEBUG] Customization status previously reported, nothing to do
  [2018-05-22T17:35:48:                              :  DEBUG] Deleting &quot;C:\Windows\TEMP\vmw857B.tmp&quot; ...
  [2018-05-22T17:35:48:                              :  DEBUG] Deleted folder &quot;C:\Windows\TEMP\vmw857B.tmp&quot; .
  [2018-05-22T17:35:48:                              :   INFO] GuestCustUtil exiting.
  </code></pre>
  <p><strong>Terraform file</strong></p>
  <pre><code>/*
      Secrets
  */
  provider &quot;vault&quot; {
      address = &quot;https://&lt;removed&gt;:8200&quot;
      token = &quot;&lt;removed&gt;&quot;
  }
  
  data &quot;vault_generic_secret&quot; &quot;terraform_secrets&quot; {
      path = &quot;secret/serviceaccounts/default_group&quot;
  }
  
  provider &quot;vsphere&quot; {
      user           = &quot;${data.vault_generic_secret.terraform_secrets.data[&quot;username&quot;]}@${data.vault_generic_secret.terraform_secrets.data[&quot;domain_fqdn&quot;]}&quot;
      password       = &quot;${data.vault_generic_secret.terraform_secrets.data[&quot;password&quot;]}&quot;
      vsphere_server = &quot;&lt;removed&gt;&quot;
  }
  
  /*
      Variables
  */
  
  #The template to use for creation of new Virtual Machine
  variable &quot;Template&quot; { default = &quot;W2012R2_RELEASE&quot; }
  #The Resource Pool where the new VM should be created
  variable &quot;ResourcePool&quot; { default = &quot;Self-Service&quot; }
  #The folder where the new VM should be located
  variable &quot;Folder&quot; { default = &quot;AIS1EM&quot; }
  
  /*  
      VM Build
  */
  data &quot;vsphere_datacenter&quot; &quot;dc&quot; {
      name = &quot;Data Center&quot;
  }
  
  data &quot;vsphere_datastore&quot; &quot;datastore&quot; {
      name          = &quot;vsanDatastore&quot;
      datacenter_id = &quot;${data.vsphere_datacenter.dc.id}&quot;
  }
  
  data &quot;vsphere_resource_pool&quot; &quot;pool&quot; {
      name          = &quot;${var.ResourcePool}&quot;
      datacenter_id = &quot;${data.vsphere_datacenter.dc.id}&quot;
  }
  
  
  data &quot;vsphere_distributed_virtual_switch&quot; &quot;dvs&quot; {
      name = &quot;DSwitch0&quot;
      datacenter_id = &quot;${data.vsphere_datacenter.dc.id}&quot;
  }
  
  data &quot;vsphere_network&quot; &quot;network&quot; {
      name = &quot;DPortGroup-VM-VLAN59&quot;
      datacenter_id = &quot;${data.vsphere_datacenter.dc.id}&quot;
  }
  
  data &quot;vsphere_virtual_machine&quot; &quot;template&quot; {
      name          = &quot;${var.Template}&quot;
      datacenter_id = &quot;${data.vsphere_datacenter.dc.id}&quot;
  }
  
  # clone from template
  resource &quot;vsphere_virtual_machine&quot; &quot;Clone&quot; {
      name             = &quot;AIS1EM-SAMSON&quot;
      resource_pool_id = &quot;${data.vsphere_resource_pool.pool.id}&quot;
      datastore_id     = &quot;${data.vsphere_datastore.datastore.id}&quot;
      wait_for_guest_net_timeout = false
      num_cpus = 2
      memory   = 4096
      guest_id = &quot;${data.vsphere_virtual_machine.template.guest_id}&quot;
      scsi_type = &quot;${data.vsphere_virtual_machine.template.scsi_type}&quot;
  
      network_interface {
          network_id = &quot;${data.vsphere_network.network.id}&quot;
          adapter_type = &quot;vmxnet3&quot;
      }
  
      disk {
          label             = &quot;AIS1EM-SAMSON.vmdk&quot;
          size             = &quot;${data.vsphere_virtual_machine.template.disks.0.size}&quot;
          eagerly_scrub    = &quot;${data.vsphere_virtual_machine.template.disks.0.eagerly_scrub}&quot;
          thin_provisioned = &quot;${data.vsphere_virtual_machine.template.disks.0.thin_provisioned}&quot;
      }
  
      clone {
              template_uuid = &quot;${data.vsphere_virtual_machine.template.id}&quot;
  
          customize {
  
              windows_options {
                  computer_name = &quot;AIS1EM-SAMSON&quot;
                  #join_domain    = &quot;&lt;removed&gt;&quot;
                  #domain_admin_user = &quot;&lt;removed&gt;&quot;
                  #domain_admin_password = &quot;&lt;removed&gt;&quot;
                  admin_password = &quot;&lt;removed&gt;&quot;
              }
  
          network_interface {
              ipv4_address = &quot;192.168.59.50&quot;
              ipv4_netmask = &quot;24&quot;
              dns_server_list = [&quot;192.168.72.167&quot;, &quot;192.168.72.168&quot;]
              #dns_domain = &quot;emisais.com&quot;
          }
  
          ipv4_gateway    = &quot;192.168.59.1&quot;
  
          }
  
      }
  }
  
  output &quot;ID&quot; {
      value = &quot;${data.vsphere_network.network.id}&quot;
  }
  </code></pre>