# Error while creating a VM

**URL:** <https://discuss.hashicorp.com/t/error-while-creating-a-vm/55345>\
**Category:** VMware\
**Created:** [June 23, 2023, 9:51am UTC](https://discuss.hashicorp.com/t/error-while-creating-a-vm/55345 "2023-06-23T09:51:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rantonelli0104](https://avatars.discourse-cdn.com/v4/letter/r/a4c791/32.png) [@rantonelli0104](https://discuss.hashicorp.com/u/rantonelli0104)\
**Post date:** [June 23, 2023, 9:51am UTC](https://discuss.hashicorp.com/t/error-while-creating-a-vm/55345/1 "2023-06-23T09:51:16Z")

</div>

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\_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 = “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”  
> # },  
> }  
> }

---

<div class="post-metadata">

**Author:** ![maxb](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/maxb/32/26655_2.png) [@maxb](https://discuss.hashicorp.com/u/maxb)\
**Post date:** [June 23, 2023, 12:48pm UTC](https://discuss.hashicorp.com/t/error-while-creating-a-vm/55345/2 "2023-06-23T12:48:11Z")

</div>

Hi @rantonelli0104 ,

I think you may find it difficult to get help on this in this forum, as this isn’t the first time recently someone has mentioned an error like this, and I don’t remember seeing a reply.

Part of the problem, is that the question, as currently phrased, requires someone have experience of both vSphere and Terraform to be able to help at all - and realistically they probably need a vSphere test environment too.

You might consider turning on very verbose logging for Terraform providers, by setting the environment variable `TF_LOG_PROVIDER=trace` - this might allow you to figure out exactly what operation is failing, which might lead to you figuring out the problem yourself - or being able to decompose it into more of a “Terraform” problem, or a “vSphere” problem - possibly allowing you to get help from people who are expert in only one product.

---

<div class="post-metadata">

**Author:** ![maxb](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/maxb/32/26655_2.png) [@maxb](https://discuss.hashicorp.com/u/maxb)\
**Post date:** [June 23, 2023, 12:48pm UTC](https://discuss.hashicorp.com/t/error-while-creating-a-vm/55345/3 "2023-06-23T12:48:41Z")

</div>

Additionally, [Welcome to the forum - please reformat your message](https://discuss.hashicorp.com/t/welcome-to-the-forum-please-reformat-your-message/52796)
