hashicorp / terraform-provider-vsphere

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

vsphere_virtual_machine : running scripts against vm built from a packer/vsphere-iso image exported as OVF #2013

Open adeturner opened 1 year ago

adeturner commented 1 year ago

Community Guidelines

Terraform

latest

Terraform Provider

v2.4.2

VMware vSphere

7

Description

If I create a Packer vsphere-iso image and export it as a OVF, and then try to instantiate it via vsphere_virtual_machine there is currently no easy way that I can run scripts against the VM.

There are three blockers from a terraform perspective

I've raised a packer problem for the same issue vsphere-iso: running scripts against terraform created VM from vsphere-iso exported as OVF #305

Are there any good examples of workarounds for this problem?

Affected Resources or Data Sources

resource/vsphere_virtual_machine

Terraform Configuration

resource "vsphere_virtual_machine" "myvm" {
  name             = local.hostname
  datastore_id     = data.vsphere_datastore.datastore.id
  resource_pool_id = vsphere_resource_pool.workload_rp.id
  folder           = vsphere_folder.workload_folder.path

  wait_for_guest_net_timeout = 5
  firmware                   = "efi"

  network_interface {
    network_id = data.vsphere_network.network.id
  }

  disk {
    label       = "disk0"
    size        = 40
    unit_number = 0 # must be unique (default 0)
  }

  clone {
    # https://registry.terraform.io/providers/hashicorp/vsphere/latest/docs/resources/virtual_machine#creating-a-virtual-machine-from-a-template
    template_uuid = data.vsphere_content_library_item.RUNNER_OVF.id
    customize {
      # ... other configuration ...
      linux_options {
        host_name = lower(local.hostname)
        domain    = var.network_domain_str

        # Add support for [Option to enable vmware-toolbox-cmd config set deployPkg enable-custom-scripts true]
        # https://github.com/hashicorp/terraform-provider-vsphere/issues/1915
        #script_text = local.custom_data_myvm
      }
    }
  }

  /*
  extra_config = {
    # guestinfo.userdata in extra_config not passed to resource configuration when using OVF
    # https://github.com/hashicorp/terraform-provider-vsphere/issues/1124
    "guestinfo.userdata"          = base64encode(local.custom_data_myvm)
    "guestinfo.userdata.encoding" = "base64"
  }

  vapp {
    # cant set these as its an enhancement still:
    # https://github.com/hashicorp/packer-plugin-vsphere/issues/44
    properties = {
      user-data = base64encode(local.custom_data_myvm)
    }
  }
  */
}

Debug Output

n/a

Panic Output

No response

Expected Behavior

Have at least one working option to run a script

Actual Behavior

All provider methods to do this fail

Steps to Reproduce

  1. Use packer vsphere-iso to create an OVF export
  2. Use terraform vsphere_virtual_machine to create a VM and run a script
github-actions[bot] commented 1 year ago

Hello, adeturner! 🖐

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.