Vmware vSphere vs.terraform VM自定义失败,网络未连接

Vmware vSphere vs.terraform VM自定义失败,网络未连接,vmware,terraform,Vmware,Terraform,当我试图自定义Windows虚拟机的网络接口post配置时,terraform错误,虚拟机在没有连接NIC的情况下运行 版本 地形=v0.11.7 vSphere版本=6.7.0,8169922 Windows 2012 R2的计算机克隆 到目前为止的调查 在vCenter和VM设置中,“网络适配器1”未标记为通电启动。这就好像在定制过程中丢失了此设置,从而导致缺少与VM的通信。如果我关闭服务器电源,则选中“启动时连接NIC”复选框,然后当服务器重新联机时,其网络配置正确,如“自定义”部分中所定

当我试图自定义Windows虚拟机的网络接口post配置时,terraform错误,虚拟机在没有连接NIC的情况下运行

版本
地形=v0.11.7
vSphere版本=6.7.0,8169922
Windows 2012 R2的计算机克隆

到目前为止的调查
在vCenter和VM设置中,“网络适配器1”未标记为通电启动。这就好像在定制过程中丢失了此设置,从而导致缺少与VM的通信。如果我关闭服务器电源,则选中“启动时连接NIC”复选框,然后当服务器重新联机时,其网络配置正确,如“自定义”部分中所定义。我还将定制功能剥离到最低限度,但仍然会遇到同样的问题

地形控制台输出

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 "/Data Center/vm/AIS1EM-SAMSON":
    
    
    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.
来自虚拟机的自定义文件日志

[2018-05-22T17:35:13:                              :   INFO] GuestCustUtil invoked.
[2018-05-22T17:35:13:                              :   INFO] Params: customize -sealparam "/quiet /generalize /oobe /reboot" -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: '"C:\Program Files\VMware\VMware Tools\vmtoolsd.exe" --cmd "info-set guestinfo.gc.notification Started"'
[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 <AdministratorPassword><EncryptedValue>
[2018-05-22T17:35:13:                              :  DEBUG] preTag <Credentials> not found
[2018-05-22T17:35:13:                              :  DEBUG] preTag <Password> not found
[2018-05-22T17:35:13:                              :  DEBUG] Tag  -de  not found after <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: '"C:\Program Files\VMware\VMware Tools\vmtoolsd.exe" --cmd "info-set guestinfo.gc.notification WinMgmt : "'
[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 "VMware Guest OS Customization Task"'
[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<\|/>'
[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 "VMware Guest OS Customization Task"'
[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<\|/>'
[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 "C:\Windows\TEMP\vmw857B.tmp\guestcustutil.exe post-run HandleCustomizationCompleted<\|/>" /tn "VMware Guest OS Customization Task"
[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 "C:\sysprep" ...
[2018-05-22T17:35:23:                              :  DEBUG] Deleted folder "C:\sysprep" .
[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<\|/>
[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<\|/>'
[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 "VMware Guest OS Customization Task"'
[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 "VMware Guest OS Customization Task"
[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 "C:\Windows\TEMP\vmw857B.tmp" ...
[2018-05-22T17:35:48:                              :  DEBUG] Deleted folder "C:\Windows\TEMP\vmw857B.tmp" .
[2018-05-22T17:35:48:                              :   INFO] GuestCustUtil exiting.
调用了GuestCustUtil。 [2018-05-22T17:35:13::INFO]参数:定制-sealparam“/quiet/generalize/oobe/reboot”-NIC 4000-ScheduleNativeUnbofusc [2018-05-22T17:35:13::DEBUG]未设置注册表值“CustomRescheduleFlags”。正在返回默认值:0 [2018-05-22T17:35:13::INFO]正在检查Windows Sysprep重新专业化操作。 [2018-05-22T17:35:13::调试]Sysprep进程未运行。 [2018-05-22T17:35:13::INFO]未检测到Windows Sysprep重新专业化操作。 [2018-05-22T17:35:13:GuestCustomutil:DEBUG]删除状态标记文件C:/Windows/.post gc状态 [2018-05-22T17:35:13:GuestCustUtil:DEBUG]状态标记文件C:/Windows/。post gc状态不存在 [2018-05-22T17:35:13::INFO]未启用扩展自定义! [2018-05-22T17:35:13::调试]已开始手动定制 [2018-05-22T17:35:13::调试]正在进行的自定义在2018-5-22 17:35:13设置为1 [2018-05-22T17:35:13::调试]已启用GOSCPostreBottoStatus功能 [2018-05-22T17:35:13:GuestCustomutil:DEBUG]SetVmxProperty:key-'guestinfo.gc.notification',value-'Started' [2018-05-22T17:35:13:WindowsOSAbstrationLayer:INFO]VMware tools安装路径=C:\Program Files\VMware\VMware tools\ [2018-05-22T17:35:13:WindowsOSAbstrationLayer:INFO]正在执行命令:““C:\Program Files\VMware\VMware Tools\vmtoolsd.exe”--cmd“INFO set guestinfo.gc.notification Started”” [2018-05-22T17:35:13:WindowsOSAbstrationLayer:INFO]命令执行成功,输出:' ' [2018-05-22T17:35:13::DEBUG]Rpci:发送请求='deployPkg.update.state 40 C:/Windows/TEMP/vmware imc/guestcust.log' [2018-05-22T17:35:13::DEBUG]Rpci:Sent request='deployPkg.update.state 40 C:/Windows/TEMP/vmware imc/guestcust.log',reply='',len=0,status=1 [2018-05-22T17:35:13::DEBUG]临时sysprep目录路径:C:\sysprep [2018-05-22T17:35:13::DEBUG]正在将文件/目录从“sysprep”复制到“C:\sysprep” [2018-05-22T17:35:13::INFO]Sysprep文件是C:\Windows\Panther\unattend.xml [2018-05-22T17:35:13::INFO]正在进行密码解密 [2018-05-22T17:35:13::调试]解密密码 [2018-05-22T17:35:13::调试]为找到密码并解密 [2018-05-22T17:35:13::调试]找不到preTag [2018-05-22T17:35:13::调试]找不到preTag
[2018-05-22T17:35:13::DEBUG]Tag-de在之后未找到。您可能需要确保您的VM模板尚未进行系统准备

我遇到了与您相同的问题,一旦使用了一个没有sysprep的模板(我相信Terraform会sysprep它),网络适配器将在定制过程中的正确时间连接

/*
    Secrets
*/
provider "vault" {
    address = "https://<removed>:8200"
    token = "<removed>"
}

data "vault_generic_secret" "terraform_secrets" {
    path = "secret/serviceaccounts/default_group"
}

provider "vsphere" {
    user           = "${data.vault_generic_secret.terraform_secrets.data["username"]}@${data.vault_generic_secret.terraform_secrets.data["domain_fqdn"]}"
    password       = "${data.vault_generic_secret.terraform_secrets.data["password"]}"
    vsphere_server = "<removed>"
}

/*
    Variables
*/

#The template to use for creation of new Virtual Machine
variable "Template" { default = "W2012R2_RELEASE" }
#The Resource Pool where the new VM should be created
variable "ResourcePool" { default = "Self-Service" }
#The folder where the new VM should be located
variable "Folder" { default = "AIS1EM" }

/*  
    VM Build
*/
data "vsphere_datacenter" "dc" {
    name = "Data Center"
}

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

data "vsphere_resource_pool" "pool" {
    name          = "${var.ResourcePool}"
    datacenter_id = "${data.vsphere_datacenter.dc.id}"
}


data "vsphere_distributed_virtual_switch" "dvs" {
    name = "DSwitch0"
    datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

data "vsphere_network" "network" {
    name = "DPortGroup-VM-VLAN59"
    datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

data "vsphere_virtual_machine" "template" {
    name          = "${var.Template}"
    datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

# clone from template
resource "vsphere_virtual_machine" "Clone" {
    name             = "AIS1EM-SAMSON"
    resource_pool_id = "${data.vsphere_resource_pool.pool.id}"
    datastore_id     = "${data.vsphere_datastore.datastore.id}"
    wait_for_guest_net_timeout = false
    num_cpus = 2
    memory   = 4096
    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}"
        adapter_type = "vmxnet3"
    }

    disk {
        label             = "AIS1EM-SAMSON.vmdk"
        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}"
    }

    clone {
            template_uuid = "${data.vsphere_virtual_machine.template.id}"

        customize {

            windows_options {
                computer_name = "AIS1EM-SAMSON"
                #join_domain    = "<removed>"
                #domain_admin_user = "<removed>"
                #domain_admin_password = "<removed>"
                admin_password = "<removed>"
            }

        network_interface {
            ipv4_address = "192.168.59.50"
            ipv4_netmask = "24"
            dns_server_list = ["192.168.72.167", "192.168.72.168"]
            #dns_domain = "emisais.com"
        }

        ipv4_gateway    = "192.168.59.1"

        }

    }
}

output "ID" {
    value = "${data.vsphere_network.network.id}"
}