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

Closed
4 tasks done
sshirata2 opened this issue Apr 11, 2024 · 5 comments · Fixed by #2216
Closed
4 tasks done

ovf_deploy fails in Terraform on Windows 10 #2166

sshirata2 opened this issue Apr 11, 2024 · 5 comments · Fixed by #2216
Assignees
Labels
bug Type: Bug
Milestone

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           = "[email protected]"
  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.

@vaerh
Copy link

vaerh commented Jun 11, 2024

@tenthirtyam @vasilsatanasov
Colleagues, I also have problems with an error when using the filepath.Join function in Windows.

image
image

@tenthirtyam tenthirtyam added this to the Backlog milestone Jun 12, 2024
@tenthirtyam
Copy link
Collaborator

I think this should be changed to the following, esp since it's not actually a filepath but rather an inventory path in vSphere.

import "path"

// ...

if ovfHelper.Folder != nil && len(ovfHelper.Folder.InventoryPath) > 0 {
    searchPath = path.Join(ovfHelper.Folder.InventoryPath, searchPath)
}

Assigning to myself.

@tenthirtyam tenthirtyam self-assigned this Jun 14, 2024
@tenthirtyam tenthirtyam modified the milestones: Backlog, v2.8.2 Jun 14, 2024
tenthirtyam added a commit that referenced this issue Jun 14, 2024
Updates `searchPath` to use `path` instead of `filepath` since this is a vSphere inventory path (e.g., `\Datacenter\vm\<vm_name>`), not a directory path.

Ref: #2166

Signed-off-by: Ryan Johnson <[email protected]>
Copy link

This functionality has been released in v2.8.2 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 30, 2024
@tenthirtyam tenthirtyam removed the needs-triage Status: Issue Needs Triage label Aug 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Type: Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants