terraform-provider-vsphere: v1.17.0 - vsphere_virtual_machine : Invalid operation for device '0'
Hello,
I’m currently unable to deploy VMs using the terraform-provider-vsphere 1.17.0 and I’m getting :
vsphere_virtual_machine.svvm: Creating… vsphere_virtual_machine.svvm: Still creating… [10s elapsed] Error: error reconfiguring virtual machine: error reconfiguring virtual machine: Invalid operation for device ‘0’.
with the version 1.15, the VM is created with the same configuration
Terraform Version
Terraform v0.12.24
vSphere Provider Version
provider.vsphere = 1.17.0
Affected Resource(s)
vsphere_virtual_machine
Terraform Configuration Files
variable "dns_servers" {}
variable "domain" {}
variable "vsphere_datacenter" {}
variable "vsphere_cluster" {}
variable "vsphere_datastore" {}
variable "vsphere_template" {}
variable "vsphere_folder" {}
variable "vsphere_network" {}
data "vsphere_datacenter" "datacenter" {
name = var.vsphere_datacenter
}
data "vsphere_resource_pool" "cluster" {
name = "${var.vsphere_cluster}/Resources"
datacenter_id = data.vsphere_datacenter.datacenter.id
}
data "vsphere_datastore" "datastore" {
name = var.vsphere_datastore
datacenter_id = data.vsphere_datacenter.datacenter.id
}
data "vsphere_virtual_machine" "template" {
name = var.vsphere_template
datacenter_id = data.vsphere_datacenter.datacenter.id
}
data "vsphere_network" "network" {
name = var.vsphere_network
datacenter_id = data.vsphere_datacenter.datacenter.id
}
resource "vsphere_virtual_machine" "svvm" {
name = "testvm5"
folder = ""
num_cpus = 1
memory = 1024
memory_hot_add_enabled = true
cpu_hot_add_enabled = true
cpu_hot_remove_enabled = true
datastore_id = data.vsphere_datastore.datastore.id
resource_pool_id = data.vsphere_resource_pool.cluster.id
guest_id = data.vsphere_virtual_machine.template.guest_id
scsi_type = data.vsphere_virtual_machine.template.scsi_type
network_interface {
network_id = data.vsphere_network.network.id
}
disk {
label = "disk0"
size = data.vsphere_virtual_machine.template.disks.0.size
eagerly_scrub = data.vsphere_virtual_machine.template.disks.0.eagerly_scrub
thin_provisioned = data.vsphere_virtual_machine.template.disks.0.thin_provisioned
}
clone {
template_uuid = data.vsphere_virtual_machine.template.id
customize {
timeout = 30
linux_options {
host_name = "testvm"
domain = "vm.lab.platform-essential.com"
}
}
}
}
Debug Output
https://gist.github.com/derrar05aiss/f29196d83eb90dc21380b11eca8c39d5
Expected Behavior
VM creation
Actual Behavior
Error while reconfiguring the VM
Steps to Reproduce
Please list the steps required to reproduce the issue, for example:
terraform apply
References
Are there any other GitHub issues (open or closed) or Pull Requests that should be linked here?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 11
- Comments: 16 (5 by maintainers)
Definetively the issue is in the provider as pointed by @derrar05aiss
I can create the VM forcing the provider to 1.15
I believe this issue was fixed by #1397, included in the 2.0.0 release.
@gitnetofr : the root issue appears to result from the
vsphere_virtual_machinedata source and resource types measuring disk size in integer GiB, whilst real-world templates may have non-integer GiB disk sizes (e.g. Packer/vsphere-iso still expects sizes in integer MiB). Integer arithmetic interraform-provider-vsphereresults in these non-integer GiB disk sizes being rounded down to the nearest GiB. Unfortunately, when you clone using the rounded down size, you’re implicitly telling vSphere to shrink the disk, which is unsupported, and results in theInvalid operation for device '0'error.I’ve opened #1397 with a fix.
It could even be both. Packer does something that it shouldn’t, leaving the VM in an odd state Terraform should handle that and make it work anyhow
Will close, if the issue persists after upgrading to v2.0.0 of the provider please feel free to comment for re-evaluation
I found the root cause of this issue by investigating differences between 1.15.0 and 1.16.0 releases.
Investigation logs
First, i activated
client_debuginvsphereprovider to log SOAP requests and responses into~/.govmomi/folder. A difference appears inReconfigVM_Taskrequest. In fact, an additionaleditoperation on hard drive is present in the 1.16.0 request. This operation appears at rank0.The related error message is following.
So, the first clue seems to be the
diskdevice.Then, I decided to compile every commits between 1.15.0 and 1.16.0 and redo the same test with the compiled plugin by using
dev_overridesin~/.terraformrc. I discovered that the commit bc1eb533f4a504fb3fdd4614ea77faef45d36f68 reveals the issue. This commit adds the Storage Policy Based Management).The second clue is the
storage_policy_idparameter that has been added in 1.16.0 version.Solution
In order to get the name of the Storage Policy at VM and disk levels, follow these instructions:
ConfigureandPoliciesto get the namesSee below the updates required to fix the issue.
Yes same issue here : error reconfiguring virtual machine: error reconfiguring virtual machine: Invalid operation for device ‘0’. vsphere 7 and hashicorp/vsphere v1.24.3… packer version 1.6.6
forcing the provider version to 1.15 helps thanks!