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

proxmox_virtual_environment_vm.virtual_machine already exists error #1413

Open
eminaktas opened this issue Jun 26, 2024 · 1 comment
Open
Labels
🐛 bug Something isn't working

Comments

@eminaktas
Copy link

Describe the bug

When vm creation fails - the error I got to complete: error retrieving task status: received an HTTP 599 response - Reason: Too many redirections, re-plan and re-apply fails to apply the replace in the sate for virtual_machine. VM is already created on first try but vm stuck at stopped status. However, the tf provider wasn't able to recover it from that state. I am already using GCS to store the state so that way I am generating the plan where I left off.

  # module.test[0].module.workers[1].proxmox_virtual_environment_vm.virtual_machine is tainted, so it must be replaced
+/- resource "proxmox_virtual_environment_vm" "virtual_machine" {
      ~ id                      = "2005" -> (known after apply)
      ~ ipv4_addresses          = [] -> (known after apply)
      ~ ipv6_addresses          = [] -> (known after apply)
      ~ mac_addresses           = [
          - "BC:24:11:FE:2C:1B",
        ] -> (known after apply)
        name                    = "k8s-worker-2-test"
      ~ network_interface_names = [] -> (known after apply)
      ~ started                 = false -> true
        tags                    = [
            "terraform",
            "worker",
        ]
        # (22 unchanged attributes hidden)

      ~ cpu {
          - flags        = [] -> null
            # (8 unchanged attributes hidden)
        }

      ~ disk {
          ~ path_in_datastore = "vm-2005-disk-5" -> (known after apply)
            # (12 unchanged attributes hidden)
        }
      ~ disk {
          ~ path_in_datastore = "vm-2005-disk-0" -> (known after apply)
            # (11 unchanged attributes hidden)
        }
      ~ disk {
          ~ path_in_datastore = "vm-2005-disk-1" -> (known after apply)
            # (11 unchanged attributes hidden)
        }
      ~ disk {
          ~ path_in_datastore = "vm-2005-disk-2" -> (known after apply)
            # (11 unchanged attributes hidden)
        }
      ~ disk {
          ~ path_in_datastore = "vm-2005-disk-3" -> (known after apply)
            # (11 unchanged attributes hidden)
        }
      ~ disk {
          ~ path_in_datastore = "vm-2005-disk-4" -> (known after apply)
            # (11 unchanged attributes hidden)
        }

      ~ initialization {
          - interface         = "ide2" -> null
          ~ upgrade           = false -> (known after apply)
            # (2 unchanged attributes hidden)

            # (2 unchanged blocks hidden)
        }

      ~ network_device {
          - disconnected = false -> null
          ~ mac_address  = "BC:24:11:FE:2C:1B" -> (known after apply)
            # (8 unchanged attributes hidden)
        }

        # (4 unchanged blocks hidden)
    }

Plan: 8 to add, 0 to change, 1 to destroy.
11512e5d15c9:/project/test# tofu apply tofu.tfplan 
Acquiring state lock. This may take a few moments...
module.test[0].module.workers[1].proxmox_virtual_environment_vm.virtual_machine: Creating...
╷
│ Error: error creating VM: received an HTTP 500 response - Reason: unable to create VM 2005 - VM 2005 already exists on node 'xxx'
│ 
│   with module.test[0].module.workers[1].proxmox_virtual_environment_vm.virtual_machine,
│   on .terraform/modules/test/modules/vm/main.tf line 1, in resource "proxmox_virtual_environment_vm" "virtual_machine":
│    1: resource "proxmox_virtual_environment_vm" "virtual_machine" {
│

To Reproduce
Steps to reproduce the behavior:

  1. Create a VM with terraform/tofu
  2. See failure creation the VM due to any reason during creating and let the tofu to store the state
  3. Plan again
  4. See the replace in the VM resource
  5. Run Apply
  6. See error

Expected behavior
Expected to see that it recovers the VM from its latest state.

  • Single or clustered Proxmox: Single
  • Proxmox version: 8.2.2
  • Provider version (ideally it should be the latest version): v0.60.0
  • Terraform/OpenTofu version: OpenTofu v1.7.2
  • OS (where you run Terraform/OpenTofu from): Alpine Linux v3.18
  • Debug logs (TF_LOG=DEBUG terraform apply): apply.log
@eminaktas eminaktas added the 🐛 bug Something isn't working label Jun 26, 2024
@vanillaSprinkles
Copy link

vanillaSprinkles commented Jul 5, 2024

it is marked as tainted; you can explicitly un-taint it (tofu untaint <tf-addr>); you can also run a state rm <tf-addr> (state remove) and import it. did you explicitly mark the item as tainted and are trying to have TF nuke the vm-id and re-create it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants