I'm a Korean worker who uses terraform codes to provision virtual machines in vcenter by using official terraform vsphere provider.
I am provisioning vms with ovf templates currently, so I tried to configure 'remote_ovf_url' of the datastore path which has ovf file.
But it seems that 'remote_ovf_url' argument doesn't mean the vcenter's datastore folder path.
Is my guess right?. If it is not, how can I find the 'remote_url_path' of the datastore?
Does vsphere provider not support the creation of virtual machines through ovf files on vcenter's content library or datastore?
data "vsphere_datacenter" "datacenter" {
name = "Datacenter"
}
data "vsphere_compute_cluster" "cluster" {
name = "새 클러스터"
datacenter_id = data.vsphere_datacenter.datacenter.id
}
data "vsphere_datastore" "datastore" {
name = "datastore1"
datacenter_id = data.vsphere_datacenter.datacenter.id
}
data "vsphere_host" "host" {
datacenter_id = data.vsphere_datacenter.datacenter.id
}
data "vsphere_network" "network" {
name = "VM Network"
datacenter_id = data.vsphere_datacenter.datacenter.id
}
data "vsphere_ovf_vm_template" "ovf" {
name = "terraform-ovf-vm"
resource_pool_id = data.vsphere_compute_cluster.cluster.resource_pool_id
host_system_id = data.vsphere_host.host.id
datastore_id = data.vsphere_datastore.datastore.id
# remote_ovf_url = "https://10.1.0.153/cls/data/293ed829-9178-4ee7-a0bf-8b57b216e423/linux-mint-2.ovf" # when export ovf, I copied its url
# remote_ovf_url = "https://10.1.0.153/ui/data/properties/urn:vmomi:Folder:group-d1:8f6de25d-8ed0-4032-b90e-b762588f4801?properties=libraryTemplates" # developer tool's (F12)
remote_ovf_url = "https://10.1.0.153/ui/app/datastore;nav=s/urn:vmomi:Datastore:datastore-15:8f6de25d-8ed0-4032-b90e-b762588f4801/files/220707_2bae2c91-0496-484c-862b-313fa67022a6.ovf" # just entered the vcenter web ui and attached ovf file to '.../files/'
} # I tried all of the tries above, but failed.
resource "vsphere_virtual_machine" "vm" {
name = "terraform-vm-ha101"
datacenter_id = data.vsphere_datacenter.datacenter.id
host_system_id = data.vsphere_host.host.id
resource_pool_id = data.vsphere_compute_cluster.cluster.resource_pool_id
datastore_id = data.vsphere_datastore.datastore.id
num_cpus = 1
memory = 1024
guest_id = "otherLinux64Guest"
wait_for_guest_net_timeout = 0
network_interface {
network_id = data.vsphere_network.network.id
}
ovf_deploy {
allow_unverified_ssl_cert = false
remote_ovf_url = data.vsphere_ovf_vm_template.ovf.remote_ovf_url
disk_provisioning = "thin"
ip_protocol = "IPV4"
ip_allocation_policy = "STATIC_MANUAL"
ovf_network_map = {
"Network 1" = data.vsphere_network.network.id
"Network 2" = data.vsphere_network.network.id
}
}
disk {
label = "disk0"
size = 16
thin_provisioned = false
}
The Terraform vSphere provider does support the creation of a virtual machine using OVF from a content library by using the vsphere_virtual_machine resource with the clone option.
# Data source for vCenter Content Library
data "vsphere_content_library" "my_content_library" {
name = "My Content Library"
}
# Data source for vCenter Content Library Item
data "vsphere_content_library_item" "my_ovf_item" {
name = "My OVF Item"
type = "ovf"
library_id = data.vsphere_content_library.my_content_library.id
}
# Deploy a VM from OVF in Content Library
resource "vsphere_virtual_machine" "vm_from_ovf" {
name = "VM from OVF"
datastore_id = data.vsphere_datastore.my_datastore.id
resource_pool_id = data.vsphere_resource_pool.my_resource_pool.id
folder = "folder/subfolder"
wait_for_guest_net_timeout = 5
disk {
label = "disk0"
size = 16
controller_type = "scsi"
}
clone {
template_uuid = data.vsphere_content_library_item.my_ovf_item.id
}
network_interface {
network_id = data.vsphere_network.my_portgroup.id
}
}
If you need to specify parameters to the OVF, you can use the vApp option.