terraform-provider-vsphere: error reconfiguring virtual machine: Invalid operation for device '0'.

Community Guidelines

  • I have read and agree to the HashiCorp Community Guidelines .
  • Vote on this issue by adding a πŸ‘ reaction to the original issue initial description to help the maintainers prioritize.
  • Do not leave β€œ+1” or other comments that do not add relevant information or questions.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Terraform

v1.3.6

Terraform Provider

v2.2.0

VMware vSphere

7.0.3

Description

hi , I want to provision two virtual machines from template, template is created from alma linux ( cloud init image). But I am getting error : Error: error reconfiguring virtual machine: error reconfiguring virtual machine: Invalid operation for device β€˜0’.

β”‚   with vsphere_virtual_machine.vm["terraVM1"],
β”‚   on Create_VMs.tf line 46, in resource "vsphere_virtual_machine" "vm":
β”‚   46: resource "vsphere_virtual_machine" "vm" {

When I try to manualy create VM through GUI in vcenter , there is no problem .

Affected Resources or Data Sources

disk {
    label            = local.disk_label
    size             = local.disk_size
    thin_provisioned = local.disk_thin
  }

disk_label          = "disk0"
    disk_size           = "16"
    disk_thin           = "true"

Terraform Configuration

main.tf


provider "vsphere" {
  user                 = var.user
  password             = var.pass
  vsphere_server       = var.vcenter
  allow_unverified_ssl = 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_id

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

  name = each.value.name

  num_cpus = local.cpu_count
  memory   = local.memory

  disk {
    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                  = "DC"
    cluster             = "CL"
    resource_pool_id    = "terra"
    datastore           = "Datastore1"
    vnic1               = "vl888"
    template            = "alma"
    cpu_count           = "2"
    memory              = "2048"
    disk_label          = "disk0"
    disk_size           = "16"
    disk_thin           = "true"
    domain              = "me.local"
    ipv4_net            = "24"
    dns                 = ["8.8.8.8", "8.8.4.4"]
    ipv4_gate           = "192.168.1.1"
 
  }

variable "vms" {
    type = map
    default = {
      terraVM1= {
        name         = "terraVM1"
        ipv4_add_mgt = "192.168.1.101"
        },
      terraVM2 = {
        name         = "terraVM2"
        ipv4_add_mgt = "192.168.1.102"
         },
    }
  }

Debug Output

Panic Output

No response

Expected Behavior

to create two virtal mashines

Actual Behavior

error

Steps to Reproduce

terrafrom plan :

Terraform will perform the following actions:

   vsphere_virtual_machine.vm["terraVM1"] 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"
      + datastore_id                            = "datastore-16"
      + default_ip_address                      = (known after apply)
      + ept_rvi_mode                            = "automatic"
      + firmware                                = "bios"
      + force_power_off                         = true
      + guest_id                                = "rhel8_64Guest"
      + guest_ip_addresses                      = (known after apply)
      + hardware_version                        = (known after apply)
      + host_system_id                          = (known after apply)
      + hv_mode                                 = "hvAuto"
      + id                                      = (known after apply)
      + ide_controller_count                    = 2
      + imported                                = (known after apply)
      + latency_sensitivity                     = "normal"
      + memory                                  = 2048
      + memory_limit                            = -1
      + memory_share_count                      = (known after apply)
      + memory_share_level                      = "normal"
      + migrate_wait_timeout                    = 30
      + moid                                    = (known after apply)
      + name                                    = "terraVM1"
      + num_cores_per_socket                    = 1
      + num_cpus                                = 2
      + power_state                             = (known after apply)
      + poweron_timeout                         = 300
      + reboot_required                         = (known after apply)
      + resource_pool_id                        = "resgroup-19007"
      + 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              = 5

      + clone {
          + template_uuid = "422d0eb1-9698-d648-70b0-2c2d1bac1140"
          + timeout       = 30
        }

      + disk {
          + attach            = false
          + controller_type   = "scsi"
          + datastore_id      = "<computed>"
          + device_address    = (known after apply)
          + disk_mode         = "persistent"
          + disk_sharing      = "sharingNone"
          + eagerly_scrub     = false
          + io_limit          = -1
          + io_reservation    = 0
          + io_share_count    = 0
          + io_share_level    = "normal"
          + keep_on_remove    = false
          + key               = 0
          + label             = "disk0"
          + path              = (known after apply)
          + size              = 16
          + storage_policy_id = (known after apply)
          + thin_provisioned  = true
          + unit_number       = 0
          + uuid              = (known after apply)
          + write_through     = false
        }

      + network_interface {
          + adapter_type          = "vmxnet3"
          + bandwidth_limit       = -1
          + bandwidth_reservation = 0
          + bandwidth_share_count = (known after apply)
          + bandwidth_share_level = "normal"
          + device_address        = (known after apply)
          + key                   = (known after apply)
          + mac_address           = (known after apply)
          + network_id            = "dvportgroup-19008"
        }
    }

   vsphere_virtual_machine.vm["terraVM2"] 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"
      + datastore_id                            = "datastore-16"
      + default_ip_address                      = (known after apply)
      + ept_rvi_mode                            = "automatic"
      + firmware                                = "bios"
      + force_power_off                         = true
      + guest_id                                = "rhel8_64Guest"
      + guest_ip_addresses                      = (known after apply)
      + hardware_version                        = (known after apply)
      + host_system_id                          = (known after apply)
      + hv_mode                                 = "hvAuto"
      + id                                      = (known after apply)
      + ide_controller_count                    = 2
      + imported                                = (known after apply)
      + latency_sensitivity                     = "normal"
      + memory                                  = 2048
      + memory_limit                            = -1
      + memory_share_count                      = (known after apply)
      + memory_share_level                      = "normal"
      + migrate_wait_timeout                    = 30
      + moid                                    = (known after apply)
      + name                                    = "terraVM2"
      + num_cores_per_socket                    = 1
      + num_cpus                                = 2
      + power_state                             = (known after apply)
      + poweron_timeout                         = 300
      + reboot_required                         = (known after apply)
      + resource_pool_id                        = "resgroup-19007"
      + 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              = 5

      + clone {
          + template_uuid = "422d0eb1-9698-d648-70b0-2c2d1bac1140"
          + timeout       = 30
        }

      + disk {
          + attach            = false
          + controller_type   = "scsi"
          + datastore_id      = "<computed>"
          + device_address    = (known after apply)
          + disk_mode         = "persistent"
          + disk_sharing      = "sharingNone"
          + eagerly_scrub     = false
          + io_limit          = -1
          + io_reservation    = 0
          + io_share_count    = 0
          + io_share_level    = "normal"
          + keep_on_remove    = false
          + key               = 0
          + label             = "disk0"
          + path              = (known after apply)
          + size              = 16
          + storage_policy_id = (known after apply)
          + thin_provisioned  = true
          + unit_number       = 0
          + uuid              = (known after apply)
          + write_through     = false
        }

      + network_interface {
          + adapter_type          = "vmxnet3"
          + bandwidth_limit       = -1
          + bandwidth_reservation = 0
          + bandwidth_share_count = (known after apply)
          + bandwidth_share_level = "normal"
          + device_address        = (known after apply)
          + key                   = (known after apply)
          + mac_address           = (known after apply)
          + network_id            = "dvportgroup-19008"
        }
    }

Plan: 2 to add, 0 to change, 0 to destroy.

Terraform apply

vsphere_virtual_machine.vm["terraVM2"]: Creating...
vsphere_virtual_machine.vm["terraVM1"]: Creating...
β•·
β”‚ Error: error reconfiguring virtual machine: error reconfiguring virtual machine: Invalid operation for device '0'.
β”‚
β”‚   with vsphere_virtual_machine.vm["terraVM2"],
β”‚   on Create_VMs.tf line 46, in resource "vsphere_virtual_machine" "vm":
β”‚   46: resource "vsphere_virtual_machine" "vm" {
β”‚
β•΅
β•·
β”‚ Error: error reconfiguring virtual machine: error reconfiguring virtual machine: Invalid operation for device '0'.
β”‚
β”‚   with vsphere_virtual_machine.vm["terraVM1"],
β”‚   on Create_VMs.tf line 46, in resource "vsphere_virtual_machine" "vm":
β”‚   46: resource "vsphere_virtual_machine" "vm" {

Environment Details

No response

Screenshots

No response

References

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 17 (1 by maintainers)

Most upvoted comments

May we ask that you please format HCL using the GotHub markdown editor for readability?