-
Notifications
You must be signed in to change notification settings - Fork 119
Problem Deleting Disk in Terraform Nutanix Provider – Incorrect Disk Removal and Index Shifting #804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
We were able to reproduce the issue. Here is the detailed RCA Context: From user's perspective, I attempted to create a Virtual Machine with 4 disks using the current approach — Inline Nested Block (a list-based schema where disks are defined directly inside the virtual_machine_v2 resource block). Terraform Config — Initial Disk Configuration for creating a VM
Once Virtual Machine creation is successful, I tried to delete the disk at index 1, now the user Terraform config looks like
Observations:
This gives the illusion to the user that the disk at index 1 was deleted, but technically:
This is the limitation with Terraform, it tracks repeated inline blocks as ordered lists and matches them by position rather than content, so any insertions, deletions, or reordering can cause it to shift items, update the wrong blocks, or destroy and recreate resources unintentionally.(The same behavior will be seen for NICS, CD_ROMS) Proposed Solution: I’m thinking of why we can’t have a dedicated resource for disks(something like nutanix_virtual_machine_disk), where each disk is a uniquely identifiable resource, can be created, modified, and deleted without impacting others and avoids index shifting issues entirely. It helps to
|
Thank you @GullapalliAkhil for your reply. I think it's a great idea to externalize the disks to another resource. This will fix the suppression bug and make disk handling simpler and more efficient. Best regards, |
Uh oh!
There was an error while loading. Please reload this page.
Terraform v1.9.6
Nutanix v2.0.0
Issue Summary
When attempting to remove a specific disk from a virtual machine using the nutanix_virtual_machine_v2 resource, Terraform does not delete the correct disk. Instead, it shifts the index of all subsequent disks, causing unintended changes to disk assignments.
Terraform Configuration Example
Given the following disk configuration:
`
disks = [
{ id = "disk-1", size_gb = 140 , index = 1 },
{ id = "disk-2", size_gb = 130 , index = 2 },
//{ id = "disk-3", size_gb = 100 , index = 3 },
{ id = "disk-4", size_gb = 40 , index = 4 },
{ id = "disk-5", size_gb = 30 , index = 5 },
{ id = "disk-6", size_gb = 40 , index = 6 }
]
`
Disks input is a list of object
nutanix_virtual_machine_v2.vm will be updated in-place
`
variable "disks" {
type = list(object({
}))
default = []
}
`
Terraform conf
` dynamic "disks" {
}
`
When I remove disk-3, I expect only disk-3 to be deleted. However, the behavior I see is that Terraform:
Deletes disk-6 instead.
Moves disk-5 → index 6
Moves disk-4 → index 5
Moves disk-3 (which is now missing) → index 4
Terraform Plan Output
`
~ update in-place
Terraform will perform the following actions:
~ resource "nutanix_virtual_machine_v2" "vm" {
`
This behavior incorrectly shifts disk indices instead of deleting disk-3 directly.
Expected Behavior
Terraform should only remove the specified disk without modifying the indices of other disks.
NB: This test is possible thanks to pull request : #761
Regards
The text was updated successfully, but these errors were encountered: