terraform {
required_providers {
vsphere = {
source = "hashicorp/vsphere"
version = "2.3.1"
}
}
}
provider "vsphere" {
user = var.vsphere_user
password = var.vsphere_password
vsphere_server = var.vsphere_server_url
allow_unverified_ssl = true
}
##################################################################
# Variable
##################################################################
variable "instance_count" {
default = 1 # Number of hosts to deploy
}
##################################################################
# Data
##################################################################
data "vsphere_datacenter" "datacenter" {
name = var.datacenter
}
data "vsphere_datastore" "datastore" {
name = var.datastore_name
datacenter_id = data.vsphere_datacenter.datacenter.id
}
data "vsphere_compute_cluster" "cluster" {
name = "xxxxxxxxx.clu1"
datacenter_id = data.vsphere_datacenter.datacenter.id
}
data "vsphere_resource_pool" "pool" {
name = format("%s%s", data.vsphere_compute_cluster.cluster.name, "/Resources")
datacenter_id = data.vsphere_datacenter.datacenter.id
}
data "vsphere_network" "network" {
name = var.network_interface_name
datacenter_id = data.vsphere_datacenter.datacenter.id
}
data "vsphere_host" "host" {
name = "xxxxxxxxxxxxxxxxx"
datacenter_id = data.vsphere_datacenter.datacenter.id
}
data "vsphere_ovf_vm_template" "ovf" {
name = "foo"
resource_pool_id = data.vsphere_resource_pool.pool.id
datastore_id = data.vsphere_datastore.datastore.id
host_system_id = data.vsphere_host.host.id
local_ovf_path = "C:/Users/xxxxxxx/Downloads/xxxxxx.ovf"
#disk_provisioning = "thin"
#deployment_option = "xsmall" # xsmall, small, medium, large
#ip_protocol = "IPv4"
# ovf_network_map = {
# "Network 1" = data.vsphere_network.network.id
# }
}
##################################################################
# Resource
##################################################################
resource "vsphere_virtual_machine" "vm" {
count = var.instance_count
datacenter_id = data.vsphere_datacenter.datacenter.id
name = "vRLI-${count.index + 1}"
#num_cpus = data.vsphere_ovf_vm_template.ovf.num_cpus
#memory = data.vsphere_ovf_vm_template.ovf.memory
#guest_id = data.vsphere_ovf_vm_template.ovf.guest_id
resource_pool_id = data.vsphere_ovf_vm_template.ovf.resource_pool_id
datastore_id = data.vsphere_ovf_vm_template.ovf.datastore_id
host_system_id = data.vsphere_ovf_vm_template.ovf.host_system_id
wait_for_guest_net_timeout = 0
wait_for_guest_ip_timeout = 0
# dynamic "network_interface" {
# for_each = data.vsphere_ovf_vm_template.ovf.ovf_network_map
# content {
# network_id = network_interface.value
# }
# }
ovf_deploy {
local_ovf_path = data.vsphere_ovf_vm_template.ovf.local_ovf_path
#disk_provisioning = data.vsphere_ovf_vm_template.ovf.disk_provisioning
#deployment_option = data.vsphere_ovf_vm_template.ovf.deployment_option
#ip_protocol = data.vsphere_ovf_vm_template.ovf.ip_protocol
#ovf_network_map = data.vsphere_ovf_vm_template.ovf.ovf_network_map
}
extra_config = {
"guestinfo.metadata" = base64encode(file("${path.module}/templates/metadata.yaml"))
"guestinfo.metadata.encoding" = "base64"
"guestinfo.userdata" = base64encode(file("${path.module}/templates/userdata.yaml"))
"guestinfo.userdata.encoding" = "base64"
}
# lifecycle {
# ignore_changes = [
# annotation,
# vapp[0].properties
# ]
# }
}
#eof
Error
$ terraform apply -auto-approve
data.vsphere_datacenter.datacenter: Reading...
data.vsphere_datacenter.datacenter: Read complete after 0s [id=datacenter-1001]
data.vsphere_compute_cluster.cluster: Reading...
data.vsphere_host.host: Reading...
data.vsphere_network.network: Reading...
data.vsphere_datastore.datastore: Reading...
data.vsphere_datastore.datastore: Read complete after 0s [id=datastore-1071]
data.vsphere_network.network: Read complete after 0s [id=dvportgroup-8277]
data.vsphere_host.host: Read complete after 0s [id=host-1040]
data.vsphere_compute_cluster.cluster: Read complete after 0s [id=domain-c1007]
data.vsphere_resource_pool.pool: Reading...
data.vsphere_resource_pool.pool: Read complete after 0s [id=resgroup-1008]
data.vsphere_ovf_vm_template.ovf: Reading...
data.vsphere_ovf_vm_template.ovf: Read complete after 0s [id=foo]
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# vsphere_virtual_machine.vm[0] will be created
+ resource "vsphere_virtual_machine" "vm" {
+ annotation = (known after apply)
+ boot_retry_delay = 10000
+ change_version = (known after apply)
+ cpu_limit = -1
+ cpu_share_count = (known after apply)
+ cpu_share_level = "normal"
+ datacenter_id = "datacenter-1001"
+ datastore_id = "datastore-1071"
+ default_ip_address = (known after apply)
+ ept_rvi_mode = "automatic"
+ extra_config = {
+ "guestinfo.metadata" = "bmV0d29yazoNCiAgdmVyc2lvbjogMg0KICBldGhlcm5ldHM6DQogICAgZW5zMTkyOg0KICAgICAgZGhjcDQ6IGZhbHNlDQogICAgICBhZGRyZXNzZXM6DQogICAgICAgIC0gMTAuMC4wLjIwMC8yNA0KICAgICAgZ2F0ZXdheTQ6IDEwLjAuMC4xDQogICAgICBuYW1lc2VydmVyczoNCiAgICAgICAgYWRkcmVzc2VzOg0KICAgICAgICAgIC0gMTkyLjE2OC4xLjUNCmxvY2FsLWhvc3RuYW1lOiB1YnVudHUtMDENCiNpbnN0YW5jZS1pZDogdWJ1bnR1MDE="
+ "guestinfo.metadata.encoding" = "base64"
+ "guestinfo.userdata" = "DQojY2xvdWQtY29uZmlnDQojIHVzZXJzOg0KIyAgIC0gbmFtZTogZ3JhbnQNCiMgICAgIHNzaC1hdXRob3JpemVkLWtleXM6DQojICAgICAgLSBzc2gtcnNhIEFBQUFCM056YUMxeWMyRUFBQUFEQVFBQkFBQUJBUUM4cnF4b240aFJ5VjVjTE5aY3p1SlRlOGRzWjMzaHBXSERVOTkzcjRpaVkzdDliWHFmbUlIbElaN2RUTDkzbmx2c2d6VmRPWU1WR01PSE1nL2ExWkswVlJvS1RTNUJCaEJHSmVqakRVZldSQXRlZFpiTTlKRTVISHBrcytMK25mOGNPTTE0T3MrUTNCVit6NE1qWWZJSzVaYlYwSXZVYVkwa3NjUWNFOGNab09UQzJoSHUvTVBEbmVLSnhHK0hSUUpmdnF2bld6NjkvRVh5aTlpcXRtT24wWHk5OTA1cXRiUE5sRHMxYzRxRit6WjFxUUNrTVlQMFo0QVZ2TGFQRUpabFBtRG5HcXo1czF2VmIxMzBhWGUxQTExZXE0UndndlpSeFhXOGk4OHBLcUNHUHVMUmg3YW5xdlNJMTVTTHBBMktXdnU3d0Q1Q3ZoVGlzYy82VGZWZg0KIyAgICAgc3VkbzogWydBTEw9KEFMTCkgTk9QQVNTV0Q6QUxMJ10NCiMgICAgIGdyb3Vwczogc3Vkbw0KIyAgICAgc2hlbGw6IC9iaW4vYmFzaA0KDQojIHBhY2thZ2VzOg=="
+ "guestinfo.userdata.encoding" = "base64"
}
+ extra_config_reboot_required = true
+ firmware = "bios"
+ force_power_off = true
+ guest_id = (known after apply)
+ guest_ip_addresses = (known after apply)
+ hardware_version = (known after apply)
+ host_system_id = "host-1040"
+ hv_mode = "hvAuto"
+ id = (known after apply)
+ ide_controller_count = 2
+ imported = (known after apply)
+ latency_sensitivity = "normal"
+ memory = 1024
+ memory_limit = -1
+ memory_share_count = (known after apply)
+ memory_share_level = "normal"
+ migrate_wait_timeout = 30
+ moid = (known after apply)
+ name = "vRLI-1"
+ num_cores_per_socket = 1
+ num_cpus = 1
+ power_state = (known after apply)
+ poweron_timeout = 300
+ reboot_required = (known after apply)
+ resource_pool_id = "resgroup-1008"
+ run_tools_scripts_after_power_on = true
+ run_tools_scripts_after_resume = true
+ run_tools_scripts_before_guest_shutdown = true
+ run_tools_scripts_before_guest_standby = true
+ sata_controller_count = 0
+ scsi_bus_sharing = "noSharing"
+ scsi_controller_count = 1
+ scsi_type = "pvscsi"
+ shutdown_wait_timeout = 3
+ storage_policy_id = (known after apply)
+ swap_placement_policy = "inherit"
+ tools_upgrade_policy = "manual"
+ uuid = (known after apply)
+ vapp_transport = (known after apply)
+ vmware_tools_status = (known after apply)
+ vmx_path = (known after apply)
+ wait_for_guest_ip_timeout = 0
+ wait_for_guest_net_routable = true
+ wait_for_guest_net_timeout = 0
+ disk {
+ attach = (known after apply)
+ controller_type = (known after apply)
+ datastore_id = (known after apply)
+ device_address = (known after apply)
+ disk_mode = (known after apply)
+ disk_sharing = (known after apply)
+ eagerly_scrub = (known after apply)
+ io_limit = (known after apply)
+ io_reservation = (known after apply)
+ io_share_count = (known after apply)
+ io_share_level = (known after apply)
+ keep_on_remove = (known after apply)
+ key = (known after apply)
+ label = (known after apply)
+ path = (known after apply)
+ size = (known after apply)
+ storage_policy_id = (known after apply)
+ thin_provisioned = (known after apply)
+ unit_number = (known after apply)
+ uuid = (known after apply)
+ write_through = (known after apply)
}
+ ovf_deploy {
+ allow_unverified_ssl_cert = false
+ enable_hidden_properties = false
+ local_ovf_path = "C:/Users/xxxxxx/Downloads/xxxxxxxxxxxxx.ovf"
}
}
Plan: 1 to add, 0 to change, 0 to destroy.
vsphere_virtual_machine.vm[0]: Creating...
╷
**│ Error: error while importing ovf/ova template, A specified parameter was not correct: ovfSection.info.key**
**│**
**│ with vsphere_virtual_machine.vm[0],**
**│ on main.tf line 74, in resource "vsphere_virtual_machine" "vm":**
**│ 74: resource "vsphere_virtual_machine" "vm" {**
The ova/ovf runs fine if i manually import it in to Vsphere.
I tried editing and removing lines from OVF XML without any luck by following this article (VMware OVA not compatible with terraform vSphere · Issue #120 · hashicorp/packer-plugin-vmware · GitHub)
Thought the issue was with vapp or cloud base init but that was not the case, any help would be appericated