Skip to content
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

Deleted Disk Entries Persist in State, Causing Invalid ID Errors #2297

Open
4 tasks done
iBrandyJackson opened this issue Nov 6, 2024 · 2 comments
Open
4 tasks done
Assignees
Labels
bug Type: Bug needs-triage Status: Issue Needs Triage
Milestone

Comments

@iBrandyJackson
Copy link
Member

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.0.0

Terraform Provider

v2.8.2

VMware vSphere

7

Description

When using the vsphere_virtual_machine resource in Terraform to manage VMs with multiple disks, removing a disk from the configuration leads to errors if the deleted disk remains in the state file as <deleted>. This results in Terraform attempting to manage an additional, non-existent disk, causing the error:

Error: disk.2: cannot find disk device: invalid ID

Affected Resources or Data Sources

vsphere_virtual_machine

Terraform Configuration

Initial Configuration with Two Disks

resource "vsphere_virtual_machine" "example_vm" {
  name             = "example-vm"
  resource_pool_id = "resgroup-100"
  datastore_id     = "datastore-12"
  num_cpus         = 2
  memory           = 4096
  guest_id         = "otherGuest"

  network_interface {
    network_id   = "network-100"
    adapter_type = "vmxnet3"
  }

  # Define two disks initially
  disk {
    label            = "disk0"
    size             = 100
    unit_number      = 0
    thin_provisioned = true
  }

  disk {
    label            = "disk1"
    size             = 1000
    unit_number      = 1
    thin_provisioned = true
  }
}
  1. Run terraform apply to create the VM with two disks.
  2. Modify the configuration to remove one disk, simulating what happens when a disk is deleted but retains a label in the state file:
# Modified Configuration: Removed One Disk
resource "vsphere_virtual_machine" "example_vm" {
  name             = "example-vm"
  resource_pool_id = "resgroup-100"
  datastore_id     = "datastore-12"
  num_cpus         = 2
  memory           = 4096
  guest_id         = "otherGuest"

  network_interface {
    network_id   = "network-100"
    adapter_type = "vmxnet3"
  }

  # Only one disk now, disk0
  disk {
    label            = "disk0"
    size             = 100
    unit_number      = 0
    thin_provisioned = true
  }
}
  1. In the Terraform state file, the deleted disk may appear like this:
{
  "mode": "managed",
  "type": "vsphere_virtual_machine",
  "name": "example_vm",
  "provider": "provider.vsphere",
  "instances": [
    {
      "attributes": {
        "disk": [
          {
            "label": "disk0",
            "size": 100,
            "unit_number": 0,
            "thin_provisioned": true
          },
          {
            "label": "<deleted>",
            "size": 1000,
            "unit_number": 1,
            "thin_provisioned": true
          }
        ]
      }
    }
  ]
}
  1. Re-run terraform plan or terraform apply, and Terraform will throw an error similar to:
Error: disk.1: cannot find disk device: invalid ID

Debug Output

N/A

Panic Output

N/A

Expected Behavior

Terraform should ignore any deleted disk entries in the state file, refraining from managing these resources or generating invalid ID errors.

Actual Behavior

Terraform interprets disks in the state file as existing resources, causing it to search for invalid disk IDs that no longer exist in the configuration. This leads to an invalid ID error, blocking any further plan or apply operations.

Steps to Reproduce

  1. Configure a vsphere_virtual_machine resource in Terraform with two disks.
  2. Delete one disk from the configuration but leave its entry in the state file (marked as <deleted>).
  3. Run terraform plan or terraform apply.
  4. Observe Terraform attempting to manage a non-existent disk (e.g., disk.2), which triggers the error.

Environment Details

No response

Screenshots

No response

References

No response

@iBrandyJackson iBrandyJackson added bug Type: Bug needs-triage Status: Issue Needs Triage labels Nov 6, 2024
@tenthirtyam tenthirtyam added this to the On Deck milestone Nov 12, 2024
@burnsjared0415
Copy link
Collaborator

burnsjared0415 commented Nov 12, 2024

I am not seeing this in vSphere 8, i did a new box and then delete a disk and not seeing this error, i am running

Terraform v1.9.8
on windows_amd64
+ provider registry.terraform.io/hashicorp/vsphere v1.24.3

I will build out a vsphere 7.x environment and see if i can reproduce

@burnsjared0415 burnsjared0415 added the waiting-response Status: Waiting on a Response label Nov 12, 2024
@iBrandyJackson
Copy link
Member Author

hi @burnsjared0415 - my apologies for my delay in response here. I asked the field team member to confirm with the customer they are using v7 or v8. Will response once I hear back. I would assume they are using v7.

@github-actions github-actions bot removed the waiting-response Status: Waiting on a Response label Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Type: Bug needs-triage Status: Issue Needs Triage
Projects
None yet
Development

No branches or pull requests

3 participants