Telmate / terraform-provider-proxmox

Terraform provider plugin for proxmox
MIT License
2k stars 502 forks source link

The second net1 network device cannot be removed from VM #1027

Open maksimsamt opened 1 month ago

maksimsamt commented 1 month ago

System details:

Creating new resources works as expected, two network devices are correctly created. Initial config (network snippet):

...
resource "proxmox_vm_qemu" "cloud_vm_from_packer_template" {
...
  network = {
    model    = "virtio"
    bridge   = "vmbr0"
    tag      = 1110
    firewall = false
  }
  network = {
    model    = "virtio"
    bridge   = "vmbr1"
    tag      = 1111
    firewall = false
  }
...
}
...

Decide to remove the second net1 network device, so there is only one network block in the config:

...
resource "proxmox_vm_qemu" "cloud_vm_from_packer_template" {
...
  network = {
    model    = "virtio"
    bridge   = "vmbr0"
    tag      = 1110
    firewall = false
  }
...
}
...

In terraform apply output all looks fine, the second network block should be removed and result shows as Apply complete! Resources: 0 added, 1 changed, 0 destroyed.:

proxmox_vm_qemu.cloud_vm_from_packer_template: Refreshing state... [id=***/qemu/***]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # proxmox_vm_qemu.cloud_vm_from_packer_template will be updated in-place
  ~ resource "proxmox_vm_qemu" "cloud_vm_from_packer_template" {
        id                     = "***/qemu/***"
        name                   = "***"
        tags                   = "***"
        # (65 unchanged attributes hidden)

      - network {
          - bridge    = "vmbr1" -> null
          - firewall  = false -> null
          - link_down = false -> null
          - macaddr   = "****" -> null
          - model     = "virtio" -> null
          - mtu       = 0 -> null
          - queues    = 0 -> null
          - rate      = 0 -> null
          - tag       = 1111 -> null
        }

        # (5 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

proxmox_vm_qemu.cloud_vm_from_packer_template: Modifying... [id=***/qemu/***]
proxmox_vm_qemu.cloud_vm_from_packer_template: Modifications complete after 1s [id=***/qemu/***]

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

But as a result, the second network device net1 still exists in the PVE virtual machine.

When I try to run terraform apply again, it tries to remove this network device again and again with no success.

This network device can only be removed through the Proxmox GUI.

Most likely, the same behavior will happen with the third, fourth, etc. network devices.

Tinyblargon commented 1 month ago

@maksimsamt This is an issue with a lot more things. Basically, the provider treats lots of things like lists, but proxmox has a dedicated slot for each adapter. So we can't convert between them neatly. This will get rewritten at some point.

maksimsamt commented 4 weeks ago

@Tinyblargon, So there is currently no way to handle removing additional network devices through the provider, just manually in the GUI until this is rewritten and fixed in the provider?

Tinyblargon commented 4 weeks ago

@maksimsamt you are correct.

Tinyblargon commented 2 weeks ago

@maksimsamt https://github.com/Telmate/proxmox-api-go/issues/341

maksimsamt commented 2 weeks ago

@maksimsamt Telmate/proxmox-api-go#341

Great! @Tinyblargon , Maybe it makes sense to make the same scheme as for disks? For example:

...
resource "proxmox_vm_qemu" "cloud_vm_from_packer_template" {
...
  networks = {
    network0 = {
      model    = "virtio"
      bridge   = "vmbr0"
      tag      = 1110
      firewall = false
    }
    network1 = {
      model    = "virtio"
      bridge   = "vmbr1"
      tag      = 1111
      firewall = false
    }
  }
...
}
...
Tinyblargon commented 2 weeks ago

Probably gonna do both approaches from the start.