hashicorp / terraform-provider-vsphere

Terraform Provider for VMware vSphere
https://registry.terraform.io/providers/hashicorp/vsphere/
Mozilla Public License 2.0
612 stars 449 forks source link

Deploying local ovf results in 'Error: error while importing OVF template error while uploading the file file.vmdk": dial tcp: lookup *: no such host' #1096

Closed solarmicrobe closed 4 years ago

solarmicrobe commented 4 years ago

Community Note

Terraform Version

Terraform v0.12.26

vSphere Provider Version

provider.vsphere ~> 1.18

Affected Resource(s)

vsphere_virtual_machine

Terraform Configuration Files

terraform {
  backend "local" {
    path = "state/terraform.tfstate"
  }
}

provider "vsphere" {
  user = "root" #var.vsphere_user
  password = "redacted"#var.vsphere_password
  vsphere_server = "10.20.0.3"#var.vsphere_server

  # If you have a self-signed cert
  allow_unverified_ssl = true

  version = "~> 1.18"
}

data "vsphere_datacenter" "dc" {
  name = "ha-datacenter"
}

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

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

data "vsphere_host" "host" {
  name = "terra.lab.rezzell.com"
  datacenter_id = data.vsphere_datacenter.dc.id
}

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

resource "vsphere_virtual_machine" "vmFromLocalOvf" {
  name = "infra"
  datacenter_id = data.vsphere_datacenter.dc.id
  resource_pool_id = data.vsphere_resource_pool.pool.id
  datastore_id = data.vsphere_datastore.datastore.id
  host_system_id = data.vsphere_host.host.id
  wait_for_guest_net_timeout = 0
  wait_for_guest_ip_timeout = 0

  ovf_deploy {
    local_ovf_path = "/mnt/c/Users/micro/repos/rezzell-infastructure/terraform/vm_templates/CentOS_8.0.1905_VMM/CentOS_8.0.1905_VirtualBox_Minimal_Installation_Image_LinuxVMImages.ovf"
  }
}

Debug Output

https://gist.github.com/solarmicrobe/a2533da7293ce6ed1056ac616c8f8d85

Panic Output

NA

Expected Behavior

OVF deployed

Actual Behavior

Error: error while importing OVF template error while uploading the file /mnt/c/Users/micro/repos/rezzell-infastructure/terraform/vm_templates/CentOS_8.0.1905_VMM/CentOS_8.0.1905_VirtualBox_Minimal_Installation_Image_LinuxVMImages-disk1.vmdk Post "https://*/ha-nfc/52c4481a-8954-4348-4457-479119a26938/disk-0.vmdk": dial tcp: lookup *: no such host

Steps to Reproduce

  1. terraform apply

Important Factoids

I'm running ESXi as a single node without vcenter. I downloaded the ovf from https://www.linuxvmimages.com/images/centos-8/

It looks like it gets into govmomi and is actually having an issue POSTing the vmdk to the machine but I couldn't get a good test setup going to figure out if that's something missing from me, the provider itself, the provider giving/missing input to govmomi,

References

bryantbunderson commented 4 years ago

The log seems to indicate that the datastore on the ESX host is out of space. This can happen if you apply and destroy many times. The destroy doesn't actually delete the large vmdk files when the VM is destroyed. The datastore can fill up if you don't manually delete the orphaned vmdk files.

solarmicrobe commented 4 years ago

Dang, you're right @bryantbunderson. That was not my intention. I've updated the gist to the correct error.

I don't have much space in my homelab for this machine so after a few runs I hit the space constraint. I just delete the leftovers and try again but looks like that last run of a late night to capture the error was the insufficient space.

sumitAgrawal007 commented 4 years ago

Strange. From the log, the POST vmdk URL should look like this "https://10.10.10.10/nfc/5243d2a5-89e1-d9db-c9b1-3c31bc331498/disk-0.vmdk

But its https://*/ha-nfc/5213256a-aefc-df04-7091-88145aa00e1c/disk-0.vmdk

The host ip is missing. Please check the host IP and resource pool if they are correct or not.

bryantbunderson commented 4 years ago

You can also use the resource pool associated with the ESX Host. Notice that one of its attributes is a resource pool id.

https://www.terraform.io/docs/providers/vsphere/d/host.html

resource "vsphere_virtual_machine" "vmFromLocalOvf" {
  name = "infra"
  datacenter_id = data.vsphere_datacenter.dc.id
  resource_pool_id = data.vsphere_host.host.resource_pool_id
  datastore_id = data.vsphere_datastore.datastore.id
  host_system_id = data.vsphere_host.host.id
  wait_for_guest_net_timeout = 0
  wait_for_guest_ip_timeout = 0

  ovf_deploy {
    local_ovf_path = "/mnt/c/Users/micro/repos/rezzell-infastructure/terraform/vm_templates/CentOS_8.0.1905_VMM/CentOS_8.0.1905_VirtualBox_Minimal_Installation_Image_LinuxVMImages.ovf"
  }
}
solarmicrobe commented 4 years ago

You can also use the resource pool associated with the ESX Host. Notice that one of its attributes is a resource pool id.

I was unaware of the resource_pool_id and data_center_id on vsphere_host but neither of those helped. I do have govc installed and that's how I was finding the names of those items which I didn't know (as they start with default values in what I have set up).

govc datacenter.info
Name:                ha-datacenter
  Path:              /ha-datacenter
  Hosts:             1
  Clusters:          0
  Virtual Machines:  3
  Networks:          2
  Datastores:        1
govc host.info
Name:              gaia.lab.rezzell.com
  Path:            /ha-datacenter/host/gaia.lab.rezzell.com/gaia.lab.rezzell.com
  Manufacturer:    HP
  Logical CPUs:    16 CPUs @ 2400MHz
  Processor type:  Intel(R) Xeon(R) CPU           E5620  @ 2.40GHz
  CPU usage:       168 MHz (0.4%)
  Memory:          12277MB
  Memory usage:    1898 MB (15.5%)
  Boot time:       2020-06-01 21:58:32.52489 +0000 UTC
  State:           connected
govc datastore.info
Name:        datastore1
  Path:      /ha-datacenter/datastore/datastore1
  Type:      VMFS
  URL:       /vmfs/volumes/5e3fe1ca-797d205a-6832-9c8e992b452c
  Capacity:  539.2 GB
  Free:      460.9 GB
govc pool.info gaia.lab.rezzell.com/Resources
Name:               Resources
  Path:             /ha-datacenter/host/gaia.lab.rezzell.com/Resources
  CPU Usage:        30MHz (0.2%)
  CPU Shares:       custom (9000)
  CPU Reservation:  16728MHz (expandable=false)
  CPU Limit:        16728MHz
  Mem Usage:        412MB (5.0%)
  Mem Shares:       custom (9000)
  Mem Reservation:  8209MB (expandable=false)
  Mem Limit:        8209MB

Strange. From the log, the POST vmdk URL should look like this "https://10.10.10.10/nfc/5243d2a5-89e1-d9db-c9b1-3c31bc331498/disk-0.vmdk

But its https://*/ha-nfc/5213256a-aefc-df04-7091-88145aa00e1c/disk-0.vmdk

The host ip is missing. Please check the host IP and resource pool if they are correct or not.

Do you mean something in the vsphere_host block or in the provider block? I included my minimal main.tf so if it's missing something in the above then I missed setting it.

poojatr commented 4 years ago

@solarmicrobe Did you find any solution for this problem ? I am having a similar issue.

solarmicrobe commented 4 years ago

I have not yet. I was able to spin up a VM of a base ESXi install and I was still seeing the same behavior. My next step is to get a full development environment set up for both the provider and govmomi but life/work/family have been taking most of my time the past couple of weeks. Hopefully this week🤞.

Karthikeyanraman94 commented 4 years ago

Hello Team, same error here any updates here

sumitAgrawal007 commented 4 years ago

@Karthikeyanraman94 Can you share your main.tf

Karthikeyanraman94 commented 4 years ago

data "vsphere_host" "host" { name = "keyan01.rain.local" datacenter_id = data.vsphere_datacenter.dc.id }

resource "vsphere_virtual_machine" "vmFromRemoteOvf" { name = "Dynatrace-vm1" resource_pool_id = data.vsphere_resource_pool.pool.id datastore_id = data.vsphere_datastore.datastore.id datacenter_id = data.vsphere_datacenter.dc.id host_system_id = data.vsphere_host.host.id

wait_for_guest_net_timeout = 0 wait_for_guest_ip_timeout = 0

ovf_deploy { remote_ovf_url = "https://cloud-images.ubuntu.com/releases/server/18.04/release-20200626/ubuntu-18.04-server-cloudimg-amd64.ova" disk_provisioning = "thin" ovf_network_map = { "VM Network" = data.terraform_remote_state.iaas.outputs.segment } } }

Error: error while importing ovf/ova template, error while uploading the disk ubuntu-bionic-18.04-cloudimg.vmdk error while uploading the file ubuntu-bionic-18.04-cloudimg.vmdk Post "https://keyan01.rain.local/nfc/52664264-2800-4db7-abc4-91b312f3efe9/disk-0.vmdk": dial tcp: lookup keyan01.rain.local on 127.0.0.11:53: no such host

on vms.tf line 63, in resource "vsphere_virtual_machine" "vmFromRemoteOvf":

63: resource "vsphere_virtual_machine" "vmFromRemoteOvf" {

script returned exit code 1

Karthikeyanraman94 commented 4 years ago
I have checked no space issue in Datastore or esxi host Events in Vcenter as follows: Removed Dynatrace-vm1 on keyan01.rain.local from ha-datacenter Thursday, July 02, 2020, 15:43:53 +0530 Info Dynatrace-vm1
Removed Dynatrace-vm1 on keyan01.rain.local from ha-datacenter Thursday, July 02, 2020, 15:43:52 +0530 Info Dynatrace-vm1
-- -- -- --
Created virtual machine Dynatrace-vm1 on keyan01.rain.local, in ha-datacenter Thursday, July 02, 2020, 15:38:51 +0530 Info Dynatrace-vm1
-- -- -- --
Assign a new instance UUID (5011c9ea-06f7-607d-0f8d-f45dbd99f883) to Dynatrace-vm1 Thursday, July 02, 2020, 15:38:51 +0530 Info Dynatrace-vm1
-- -- -- --
Assigned new BIOS UUID (4211e94e-4a2c-45f7-ba36-f65495fae698) to Dynatrace-vm1 on keyan01.rain.local in ha-datacenter Thursday, July 02, 2020, 15:38:51 +0530 Info Dynatrace-vm1
-- -- -- --
Creating Dynatrace-vm1 on keyan01.rain.local, in ha-datacenter Thursday, July 02, 2020, 15:38:50 +0530 Info Dynatrace-vm1
solarmicrobe commented 4 years ago

@Karthikeyanraman94 , your error is having the same resolution message but instead of the host being "*" (like my error) yours is "keyan01.rain.local". Does that DNS record exist at the DNS server it's connecting to at 127.0.0.11?

Karthikeyanraman94 commented 4 years ago

@ solarmicrobe , I'm not sure what this IP 127.0.0.11 is.. I'm using terraform inside docker, would that cause any issues..?? I'm stuck on how to proceed in this... I tried ova deploy from remote url on same esxi host keyan01.rain.local through vcenter console it worked fine... now im consuming this manually created template in my terraform scripts

sumitAgrawal007 commented 4 years ago

@Karthikeyanraman94 , do u have connectivity to the host from where you are running terraform ?

Karthikeyanraman94 commented 4 years ago

Followed this, and fixed my docker dns issue and now I'm able to ping from inside the terraform docker to esxi host https://development.robinwinslow.uk/2016/06/23/fix-docker-networking-dns/..

@solarmicrobe @sumitAgrawal007 : Thanks a lot, It's working fine now...

vinaykumar-c commented 4 years ago

@solarmicrobe Did you find any solution for your issue?. I am also facing the same issue. I'd greatly appreciate your help. Thank You.

sumitAgrawal007 commented 4 years ago

@vinaykumar-c Please check if you have connectivity to the host from the machine running terraform.

vinaykumar-c commented 4 years ago

@sumitAgrawal007 Hi Sumit, Connectivity is fine and even i can see that terraform try to deploy the VM and it failed with the error "https://*/ha-nfc/526c211d-57b7-d2e8-49f8-ffc5ecdd1ee7/disk-0.vmdk": dial tcp: lookup *: no such host" in the terraform output.

When i check the Esxi logs it stops at Reconfig VM with error "The operation is not allowed in the current state".

vinaykumar-c commented 4 years ago

@sumitAgrawal007 @solarmicrobe I think its a bug with respect to Standalone Esxi Host. When i tired deploying the OVA using Vcenter server and the Host it worked. Can someone please escalate this issue and resolve it ASAP.

solarmicrobe commented 4 years ago

I'm able to use govc to deploy the ovf. That leads me to believe it's either a configuration issue on my side or a bug in what the provider is giving to the govmomi library.

vinaykumar-c commented 4 years ago

@sumitAgrawal007 I went over the code and understood that where exactly its came out with the error. In vsphere/internal/helper/ovfdeploy/ovf_helper.go

func DeployOvfAndGetResult

            log.Printf("Uploaded %v of %v Bytes", getTotalBytesRead(&currBytesRead), totalBytes)
            if totalBytes == 0 {
                break
            }
            progress = getTotalBytesRead(&currBytesRead) * 100 / totalBytes
            nfcLease.Progress(context.Background(), int32(progress))
            time.Sleep(10 * time.Second)
        }

Its a loop and the Terrarom log prints the 1st print "Uploaded 0 of 1457102848 Bytes" and then it throws the error "https://*/ha-nfc/529f530f-0a7c-0915-014e-5b62c60194f6/disk-0.vmdk": dial tcp: lookup *: no such host

sumitAgrawal007 commented 4 years ago

@vinaykumar-c From the documentation https://www.terraform.io/docs/providers/vsphere/r/virtual_machine.html#deploying-vm-from-an-ovf-ova-template

NOTE: ovf deployment requires vCenter and is not supported on direct ESXi connections.

It is not supported in direct EXSI connection.

solarmicrobe commented 4 years ago

Thanks for finding that @sumitAgrawal007. I think that's the answer here and I'll close now.

I'm surprised this isn't supported in the provider as it works fine from the govmomi library by way of govc but maybe I can suggest a PR that will work but that's additional work later.

ghost commented 4 years ago

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!