简体   繁体   中英

Deploy OVA to VCenter with Terraform

I am by no means a knowledgeable VMWare user at this point. I think this might just be a case where I just don't understand some essential concepts.

I'm trying to deploy a VM into a VCenter, I have an OVA (template?) that I want to deploy with.

Currently I have unpacked the OVA, uploaded the VMDKs I found therein to a datastore, and then used this terraform definition:

provider "vsphere" {
  user = "${var.vsphere_user}"
  password = "${var.vsphere_password}"
  vsphere_server = "${var.vsphere_server}"
  allow_unverified_ssl = true
}

resource "vsphere_virtual_machine" "primary" {
  name =  "myvm"
  vcpu = 2
  memory = 16384
  datacenter = "${var.vsphere_datacenter}"
  resource_pool = "/DATA_CENTER/host/10.132.260.000"

  network_interface = {
    label = "Private Network - vmnic0 vmnic2"
    ipv4_address = "10.132.260.001"
    ipv4_gateway = "10.132.260.002"
    ipv4_prefix_length = 26
  }

  disk {
    datastore = "datastore1"
    vmdk = "/path/to/vmdk/"
    bootable = true
    type = "thin"
  }
}

Which gets stuck, because it can't open the VMDK.

When I deploy the OVA with ovftool the vmdk that the vm is deployed with is very different.

An error was received from the ESX host while powering on VM myvm. Failed to start the virtual machine. Module DiskEarly power on failed. Cannot open the disk '/vmfs/volumes/557fc17b-c078f45c-f5bf-002590faf644/template_folder/my_vm.vmdk' or one of the snapshot disks it depends on. The file specified is not a virtual disk

Should I be uploading the OVA file to the datastore instead and change my disk block to look like:

disk {
  datastore = "datastore1"
  template = "/path/to/ova/"
  type = "thin"
}

Or am I just out of luck here? Also, the terraform provider for vsphere doesn't correctly receive the error from VCenter and just continues to poll even though the vm failed.

OVA contains streamOptimized disks. If you directly upload to the datastore vSphere doesn't recognize it as a VMDK for a VM.

You can use vmware-vdiskmanager tool to convert the streamOptimized disk to sparse disk.

vmware-vdiskmanager -r ova_extracted.vmdk -t 0 destination.vmdk

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM