Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ovf_deploy fails in Terraform on Windows 10 #2166

Open
4 tasks done
sshirata2 opened this issue Apr 11, 2024 · 1 comment
Open
4 tasks done

ovf_deploy fails in Terraform on Windows 10 #2166

sshirata2 opened this issue Apr 11, 2024 · 1 comment
Labels
bug Type: Bug needs-triage Status: Issue Needs Triage

Comments

@sshirata2
Copy link

Community Guidelines

  • I have read and agree to the HashiCorp Community Guidelines .
  • Vote on this issue by adding a 👍 reaction to the original issue initial description to help the maintainers prioritize.
  • Do not leave "+1" or other comments that do not add relevant information or questions.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Terraform

v1.7.5

Terraform Provider

vsphere v2.7.0 on windows_amd64

VMware vSphere

8.0.2

Description

When executing "ovf_deploy" on "vsphere_virtual_machine" under Windows 10 platform, the following error message appears.
Checking with vSphere Client, OVF has been successfully deployed, but the VM is not powered on.

│ Error: error while fetching the created vm, vm '\Datacenter\vm\nested\nested-esxi01' not found
│
│   with vsphere_virtual_machine.vmFromLocalOvf,
│   on main.tf line 56, in resource "vsphere_virtual_machine" "vmFromLocalOvf":
│   56: resource "vsphere_virtual_machine" "vmFromLocalOvf" {

But, when the same code is executed on the Ubuntu 22.04 platform, no error is output, the OVF is deployed successfully and the VM powers on.

I think perhaps Pull request # 2118 is related to this issue.
When using the filepath library of the go language, /(slash) is used as the directory separator in the Linux platform, but (backslash) is used in the Windows platform.
This appears to be the cause of the "vm not found" returned from the virtualmachine.FromPath function.
When I replaced filepath to path and built, the problem did not occur.

	searchPath := ovfHelper.Name    // searchPath : nested-esxi01
	if ovfHelper.Folder != nil && len(ovfHelper.Folder.InventoryPath) > 0 {     // ovfHelper.Folder.InventoryPath : /Datacenter/vm/nested
		searchPath = filepath.Join(ovfHelper.Folder.InventoryPath, searchPath)     // searchPath : \Datacenter\vm\nested-esxi01
	}

Affected Resources or Data Sources

resource/vsphere_virtual_machine

Terraform Configuration

provider "vsphere" {
  user           = "administrator@vsphere.local"
  password       = "Password"
  vsphere_server = "vcsa10.nsxtlab.local"
  allow_unverified_ssl = true
}

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

data "vsphere_datastore" "datastore" {
  name          = "iSCSI-1"
  datacenter_id = data.vsphere_datacenter.datacenter.id
}

data "vsphere_compute_cluster" "cluster" {
  name          = "Cluster"
  datacenter_id = data.vsphere_datacenter.datacenter.id
}

data "vsphere_resource_pool" "default" {
  name          = format("%s%s", data.vsphere_compute_cluster.cluster.name, "/Resources")
  datacenter_id = data.vsphere_datacenter.datacenter.id
}

data "vsphere_host" "host" {
  name          = "esx11.nsxtlab.local"
  datacenter_id = data.vsphere_datacenter.datacenter.id
}

data "vsphere_network" "network" {
  name          = "dvpg-nested"
  datacenter_id = data.vsphere_datacenter.datacenter.id
}

data "vsphere_folder" "folder" {
  path = "/${data.vsphere_datacenter.datacenter.name}/vm/nested"
}

## Local OVF/OVA Source
data "vsphere_ovf_vm_template" "ovfLocal" {
  name              = "nested-esxi01"
  disk_provisioning = "thin"
  resource_pool_id  = data.vsphere_resource_pool.default.id
  datastore_id      = data.vsphere_datastore.datastore.id
  host_system_id    = data.vsphere_host.host.id
  local_ovf_path    = "C:/ISO/Nested_ESXi8.0u2b_Appliance_Template_v1.ova"
  ovf_network_map = {
    "VM Network" : data.vsphere_network.network.id
  }
}

## Deployment of VM from Local OVF
resource "vsphere_virtual_machine" "vmFromLocalOvf" {
  name                 = "nested-esxi01"
  folder               = trimprefix(data.vsphere_folder.folder.path, "/${data.vsphere_datacenter.datacenter.name}/vm")
  datacenter_id        = data.vsphere_datacenter.datacenter.id
  datastore_id         = data.vsphere_datastore.datastore.id
  host_system_id       = data.vsphere_host.host.id
  resource_pool_id     = data.vsphere_resource_pool.default.id
  num_cpus             = data.vsphere_ovf_vm_template.ovfLocal.num_cpus
  num_cores_per_socket = data.vsphere_ovf_vm_template.ovfLocal.num_cores_per_socket
  memory               = data.vsphere_ovf_vm_template.ovfLocal.memory
  guest_id             = data.vsphere_ovf_vm_template.ovfLocal.guest_id
  scsi_type            = data.vsphere_ovf_vm_template.ovfLocal.scsi_type
  nested_hv_enabled    = data.vsphere_ovf_vm_template.ovfLocal.nested_hv_enabled
  dynamic "network_interface" {
    for_each = data.vsphere_ovf_vm_template.ovfLocal.ovf_network_map
    content {
      network_id = network_interface.value
    }
  }
  wait_for_guest_net_timeout = 0
  wait_for_guest_ip_timeout  = 0

  ovf_deploy {
    allow_unverified_ssl_cert = false
    local_ovf_path            = data.vsphere_ovf_vm_template.ovfLocal.local_ovf_path
    disk_provisioning         = data.vsphere_ovf_vm_template.ovfLocal.disk_provisioning
    ip_protocol               = "IPV4"
    ip_allocation_policy      = "STATIC_MANUAL"
    ovf_network_map           = data.vsphere_ovf_vm_template.ovfLocal.ovf_network_map
  }

  vapp {
    properties = {
      "guestinfo.hostname"  = "nested-esxi01.nsxtlab.local",
      "guestinfo.ipaddress" = "192.168.76.41",
      "guestinfo.netmask"   = "255.255.255.0",
      "guestinfo.gateway"   = "192.168.76.254",
      "guestinfo.dns"       = "192.168.76.241",
      "guestinfo.domain"    = "nsxtlab.local",
      "guestinfo.ntp"       = "192.168.76.241",
      "guestinfo.password"  = "Password",
      "guestinfo.ssh"       = "True"
    }
  }

  lifecycle {
    ignore_changes = [
      annotation,
      disk[0].io_share_count,
      disk[1].io_share_count,
      disk[2].io_share_count,
      vapp[0].properties,
    ]
  }
}

Debug Output

https://gist.github.com/sshirata2/8ae04479866db6f8363c0d2e02fdddd2

Panic Output

No response

Expected Behavior

Ovf is deployed and the virtual machine is powered on.

Actual Behavior

Error was output and Apply failed.

Steps to Reproduce

terraform apply

Environment Details

Windwos 10 22H2

Screenshots

No response

References

#2118

@sshirata2 sshirata2 added bug Type: Bug needs-triage Status: Issue Needs Triage labels Apr 11, 2024
Copy link

Hello, sshirata2! 🖐

Thank you for submitting an issue for this provider. The issue will now enter into the issue lifecycle.

If you want to contribute to this project, please review the contributing guidelines and information on submitting pull requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Type: Bug needs-triage Status: Issue Needs Triage
Projects
None yet
Development

No branches or pull requests

1 participant