Closed skupfer closed 2 years ago
Hello, skupfer! π
Thank you for submitting an issue for this provider. The issue will now enter into the issue lifecycle.
If you want to contribute to this project, please review the contributing guidelines and information on submitting pull requests.
Reminds me of similar issue GH-1678 - you'll need a depends_on
to force the removal of the disk before the deletion of the virtual machine.
Ryan Johnson Senior Staff Solutions Architect | Product Engineering @ VMware, Inc.
Duplicate of #1678.
It is indeed a duplicate but I haven't found this. I gave it a try and due to "A single static variable reference is required" i tried linking it to the first vm created
depends_on = [vsphere_virtual_machine.vms[0]]
or
depends_on = [vsphere_virtual_machine.vms]
but it does not create the virtual_disk and fails because it cannot find it. From the linked issue I got that I have to add the depends_on on the r/vsphere_virtual_disk.
# vsphere_virtual_disk.PersistentDataDisk[0] will be created
+ resource "vsphere_virtual_disk" "PersistentDataDisk" {
+ adapter_type = "lsiLogic"
+ create_directories = true
+ datacenter = "LP"
+ datastore = "S-LP11"
+ id = (known after apply)
+ size = 10
+ type = "thin"
+ vmdk_path = "persistent_disk_storage/pdisks_persistent.vmdk"
}
# vsphere_virtual_machine.vms[0] will be created
+ resource "vsphere_virtual_machine" "vms" {
[...]
Enter a value: yes
vsphere_virtual_machine.vms[0]: Creating...
vsphere_virtual_machine.vms[0]: Still creating... [10s elapsed]
vsphere_virtual_machine.vms[0]: Still creating... [20s elapsed]
vsphere_virtual_machine.vms[0]: Still creating... [30s elapsed]
vsphere_virtual_machine.vms[0]: Still creating... [40s elapsed]
Think I don't get the correct usage
Ok, found it. I had to link it reverse.
depends_on = [data.vsphere_virtual_machine.template, vsphere_virtual_disk.PersistentDataDisk]
Thanks for your help!
Youβre welcome! Have a good weekend!
Ryan Johnson Senior Staff Solutions Architect | Product Engineering @ VMware, Inc.
I'm going to lock this issue because it has been closed for 30 days β³. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Community Guidelines
Terraform
v1.2.8
Terraform Provider
vSphere 2.0.2
VMware vSphere
v7.0.3.00700
Description
We have a case where we want to provide VMs with a persistent data disk which survives up/down-grading the template because the data is independent. The
r/vsphere_virtual_disk
data disk will get created first onterraform apply
and attached afterwards in ther/vsphere_virtual_machine
block.If running
terraform destroy
the VM will get deleted but will throw the error:I need to run the command again to finally destroy the attached disk.
I hope the provided block is enough. I think the problem is that on destruction it is handled top-down, too and therefore it tries to delete the attached disk first without detaching it first.
Affected Resources or Data Sources
resource/vsphere_virtual_machine
resource/vsphere_virtual_disk
Terraform Configuration
Debug Output
Panic Output
No response
Expected Behavior
First the VM will get destroyed, then the attached disk
Actual Behavior
Tries destroying the attached disk, destroys the VM and throws an error
Steps to Reproduce
Run
terraform apply
, thenterraform destroy
Environment Details
No response
Screenshots
No response
References
No response