josenk / terraform-provider-esxi

Terraform-provider-esxi plugin
GNU General Public License v3.0
540 stars 154 forks source link

OVF Properties are not working #156

Closed linuxcrash closed 2 years ago

linuxcrash commented 2 years ago

Describe the bug I'm trying to get the latest Ubuntu 20.04 cloud image configured through OVF Properties but after the OVA upload into ESX and having the VM powered on, nothing happens.

I have noticed that the Ubuntu cloud image does not contain the vsphere-cloudinit datasource but from your documentation there is no hint this is needed when using OVF Properties.

To Reproduce Steps to reproduce the behavior:

  1. Download latest Ubuntu 20.04 VMware OVA cloud image from https://cloud-images.ubuntu.com/focal/current/
  2. Use default OVF Properties example from your repo (Verified that OVA still supports the same OVF Properties using ovftool).
  3. Run terraform plan/apply against ESX.
  4. OVA gets uploaded but does not get configured.

Expected behavior After the OVA upload to ESX, the VM is started and the OVF Properties get applied to the VM, essentially configuring the Ubuntu system using cloud-init from the passed in user-data OVF Property.

Terraform files Main.TF

provider "esxi" {
  esxi_hostname      = var.esxi_hostname
  esxi_hostport      = var.esxi_hostport
  esxi_hostssl       = var.esxi_hostssl
  esxi_username      = var.esxi_username
  esxi_password      = var.esxi_password
}

#
# Template for initial configuration bash script
#    template_file is a great way to pass variables to
#    cloud-init
data "template_file" "userdata_default" {
  template = file("userdata.tpl")
  vars = {
    HOSTNAME = var.vm_hostname
    HELLO    = "Hello EXSI World!"
  }
}

resource "esxi_guest" "vmtest" {
  guest_name         = var.vm_hostname
  disk_store         = var.disk_store
  power              = "on"

  #
  #  Specify an ovf file to use as a source.
  #
  ovf_source        = var.ovf_file

  network_interfaces {
     virtual_network = var.virtual_network
  }

#   guestinfo = {
#     "userdata.encoding" = "gzip+base64"
#     "userdata"          = base64gzip(data.template_file.userdata_default.rendered)
#   }

  ovf_properties {
    key = "password"
    value = "Passw0rd1"
  }

  ovf_properties {
    key = "hostname"
    value = "HelloWorld"
  }

  ovf_properties {
    key = "user-data"
    value = base64encode(data.template_file.userdata_default.rendered)
  }
}

Desktop (please complete the following information):

linuxcrash commented 2 years ago

I just tried out to run the Ubuntu OVA using VMware Workstation and directly importing it through the UI in VMware Workstation. This way the OVF properties defined are working fine.

Therefore I can clearly say that the Ubuntu cloud image uses the OVF datasource but in the Terraform/ovftool/ESX case it seems the ovf properties are not properly passed in to the VM.

VMware Workstation Screenshot: image

josenk commented 2 years ago

Have you looked at this??? https://github.com/josenk/terraform-provider-esxi/issues/140

Did you look at the documentation about OVF and cloud init? https://github.com/josenk/terraform-provider-esxi/tree/master/examples-0.13/06%20OVF%20Properties

This method of injecting properties into the VM works with ovf/ova sources only. The guestinfo method ("05 CloudInit and Templates" example) can be used with any source type (vmx, ovf, ova, clone_from_vm), but requires "Cloud-Init for VMware" to be pre-installed on the source.

I doubt those public OVF images for "Cloud-init for vmware" installed...

linuxcrash commented 2 years ago

@josenk if you look at my main.tf file reported in the issue, you might find that this is exactly your example file from here: https://github.com/josenk/terraform-provider-esxi/tree/master/examples-0.13/06%20OVF%20Properties

But it does NOT work! So I have verified that the OVA properties are listed from the Ubuntu provided cloud image using the "ovatool" and they are all shown in the output. But for whatever reason when using your provider, these properties seem not to be applied when terraform creates the VM on an ESX server. So I wonder what is missing here...

linuxcrash commented 2 years ago

@josenk bumping the issue - Any news or inputs here?

josenk commented 2 years ago

Try adding this setting to your main.tf.

ovf_properties_timer = 30

Let me know if it works better.

linuxcrash commented 2 years ago

@josenk thank you for that hint! Adding and increasing ovf_properties_timer = 60 made things starting to work! Maybe something that should be added to the example description in the OVF example section!

josenk commented 2 years ago

I will be doing an update soon to address this...

A little history. Back in V1.6.0, it was working fine, but then along the way the default ovf_properties_timer got set to 0 by mistake. So if you manually set it, things start working...

In the next release, I will make sure the default is set correctly. The 06 example will also have some extra details...