hello
i am trying to create a virtual machine with gentoo operating system with terraform leaning with VSphere(Ver8)/ESXI.
the terraform file takes a Template virtual machine and duplicates it, after that it has to configure it. When it gets to 91% of creation the following error is generated:
Error: error reconfiguring virtual machine: error reconfiguring virtual machine: Invalid operation for device ‘2’
with vspere_virtual_machine.vm[“terraVM1”], on main.ft line 39, in resource “vsphere_virtual_machine” “vm”: 39: resource “vspere_virutal_machine” “vm” {
Terraform (Ver 1.4.6) is installed on a docker container
Main.tf
provider “vsphere” {
user = “administrator@vsphere.local”
password = “M&tlab1!”
vsphere_server = “192.1.1.49”
allow_unverified_ssl = true
client_debug = true
}data “vsphere_datacenter” “dc” {
name = local.dc
}data “vsphere_compute_cluster” “compute_cluster” {
name = local.cluster
datacenter_id = data.vsphere_datacenter.dc.id
}data “vsphere_resource_pool” “pool” {
name = local.resource_pool_id
datacenter_id = data.vsphere_datacenter.dc.id
}data “vsphere_datastore” “datastore” {
name = local.datastore
datacenter_id = data.vsphere_datacenter.dc.id
}data “vsphere_network” “net” {
name = local.vnic1
datacenter_id = data.vsphere_datacenter.dc.id
}data “vsphere_virtual_machine” “template” {
name = local.template
datacenter_id = data.vsphere_datacenter.dc.id
}resource “vsphere_virtual_machine” “vm” {
for_each = var.vms
datastore_id = data.vsphere_datastore.datastore.id
resource_pool_id = data.vsphere_resource_pool.pool.id
guest_id = data.vsphere_virtual_machine.template.guest_idnetwork_interface {
network_id = data.vsphere_network.net.id
}name = each.value.name
num_cpus = local.cpu_count
memory = local.memorydisk {
label = local.disk_label
size = local.disk_size
thin_provisioned = local.disk_thin
}clone {
template_uuid = data.vsphere_virtual_machine.template.id# this part is irrelevant , because the same error occurs in both scenarios, without and with it customize { linux_options { host_name = each.value.name domain = local.domain } network_interface { ipv4_address = each.value.ipv4_add_mgt ipv4_netmask = local.ipv4_net dns_server_list = local.dns } ipv4_gateway = local.ipv4_gate }
}
}
Variables.tf
locals {
dc = “DCDEVOPS”
cluster = “LAB1”
resource_pool_id = “resource_pool_devops”
datastore = “DATASTORE8TB”
vnic1 = “VM Network”
template = “Finx4_1_VM01”
cpu_count = “4”
memory = “4096”
disk_label = “disk0”
disk_size = “50”
disk_thin = “true”
domain = “METLAB.MBDA”
ipv4_net = “24”
dns = [“8.8.8.8”, “8.8.4.4”]
ipv4_gate = “192.1.1.1”}
variable “vms” {
type = map
default = {
terraVM1= {
name = “terraVM1”
ipv4_add_mgt = “192.1.1.111”
},
# terraVM2 = {
# name = “terraVM2”
# ipv4_add_mgt = “192.1.1.112”
# },
}
}