bpg / terraform-provider-proxmox

Terraform Provider for Proxmox
https://registry.terraform.io/providers/bpg/proxmox
Mozilla Public License 2.0
884 stars 140 forks source link

fix(vm): handle more than 4 `hostpci` devices #1543

Closed bpg closed 2 months ago

bpg commented 2 months ago

Contributor's Note

Proof of Work

Using template:

resource "proxmox_virtual_environment_vm" "test_vm" {
  node_name = "pve"
  vm_id     = 999
  name      = "test-hostpci"

  started = false

  hostpci {
    device = "hostpci0"
    id     = "0000:01:00.0"
    pcie   = true
  }
  hostpci {
    device = "hostpci2"
    id     = "0000:01:00.0"
    pcie   = true
  }
  hostpci {
    device = "hostpci4"
    id     = "0000:01:00.0"
    pcie   = true
  }
  hostpci {
    device = "hostpci6"
    id     = "0000:01:00.0"
    pcie   = true
  }
  hostpci {
    device = "hostpci8"
    id     = "0000:01:00.0"
    pcie   = true
  }
}

Before the fix:

OpenTofu used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

OpenTofu will perform the following actions:

  # proxmox_virtual_environment_vm.test_vm will be created
  + resource "proxmox_virtual_environment_vm" "test_vm" {
      + acpi                    = true
      + bios                    = "seabios"
      + id                      = (known after apply)
      + ipv4_addresses          = (known after apply)
      + ipv6_addresses          = (known after apply)
      + keyboard_layout         = "en-us"
      + mac_addresses           = (known after apply)
      + migrate                 = false
      + name                    = "test-hostpci"
      + network_interface_names = (known after apply)
      + node_name               = "pve"
      + on_boot                 = true
      + protection              = false
      + reboot                  = false
      + scsi_hardware           = "virtio-scsi-pci"
      + started                 = false
      + stop_on_destroy         = false
      + tablet_device           = true
      + template                = false
      + timeout_clone           = 1800
      + timeout_create          = 1800
      + timeout_migrate         = 1800
      + timeout_move_disk       = 1800
      + timeout_reboot          = 1800
      + timeout_shutdown_vm     = 1800
      + timeout_start_vm        = 1800
      + timeout_stop_vm         = 300
      + vm_id                   = 999

      + hostpci {
          + device = "hostpci0"
          + id     = "0000:01:00.0"
          + pcie   = true
        }
      + hostpci {
          + device = "hostpci2"
          + id     = "0000:01:00.0"
          + pcie   = true
        }
      + hostpci {
          + device = "hostpci4"
          + id     = "0000:01:00.0"
          + pcie   = true
        }
      + hostpci {
          + device = "hostpci6"
          + id     = "0000:01:00.0"
          + pcie   = true
        }
      + hostpci {
          + device = "hostpci8"
          + id     = "0000:01:00.0"
          + pcie   = true
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.
proxmox_virtual_environment_vm.test_vm: Creating...
proxmox_virtual_environment_vm.test_vm: Creation complete after 1s [id=999]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
❯ tofu apply -auto-approve
proxmox_virtual_environment_vm.test_vm: Refreshing state... [id=999]

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

OpenTofu will perform the following actions:

  # proxmox_virtual_environment_vm.test_vm will be updated in-place
  ~ resource "proxmox_virtual_environment_vm" "test_vm" {
        id                      = "999"
        name                    = "test-hostpci"
        tags                    = []
        # (26 unchanged attributes hidden)

      ~ hostpci {
          ~ device = "hostpci1" -> "hostpci2"
            id     = "0000:01:00.0"
            # (3 unchanged attributes hidden)
        }
      ~ hostpci {
          ~ device = "hostpci2" -> "hostpci4"
            id     = "0000:01:00.0"
            # (3 unchanged attributes hidden)
        }
      ~ hostpci {
          ~ device = "hostpci3" -> "hostpci6"
            id     = "0000:01:00.0"
            # (3 unchanged attributes hidden)
        }
      + hostpci {
          + device = "hostpci8"
          + id     = "0000:01:00.0"
          + pcie   = true
        }

        # (1 unchanged block hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.
proxmox_virtual_environment_vm.test_vm: Modifying... [id=999]
proxmox_virtual_environment_vm.test_vm: Modifications complete after 1s [id=999]

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

After the fix:

❯ tofu apply -auto-approve
OpenTofu used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

OpenTofu will perform the following actions:

  # proxmox_virtual_environment_vm.test_vm will be created
  + resource "proxmox_virtual_environment_vm" "test_vm" {
      + acpi                    = true
      + bios                    = "seabios"
      + id                      = (known after apply)
      + ipv4_addresses          = (known after apply)
      + ipv6_addresses          = (known after apply)
      + keyboard_layout         = "en-us"
      + mac_addresses           = (known after apply)
      + migrate                 = false
      + name                    = "test-hostpci"
      + network_interface_names = (known after apply)
      + node_name               = "pve"
      + on_boot                 = true
      + protection              = false
      + reboot                  = false
      + scsi_hardware           = "virtio-scsi-pci"
      + started                 = false
      + stop_on_destroy         = false
      + tablet_device           = true
      + template                = false
      + timeout_clone           = 1800
      + timeout_create          = 1800
      + timeout_migrate         = 1800
      + timeout_move_disk       = 1800
      + timeout_reboot          = 1800
      + timeout_shutdown_vm     = 1800
      + timeout_start_vm        = 1800
      + timeout_stop_vm         = 300
      + vm_id                   = 999

      + hostpci {
          + device = "hostpci0"
          + id     = "0000:01:00.0"
          + pcie   = true
        }
      + hostpci {
          + device = "hostpci2"
          + id     = "0000:01:00.0"
          + pcie   = true
        }
      + hostpci {
          + device = "hostpci4"
          + id     = "0000:01:00.0"
          + pcie   = true
        }
      + hostpci {
          + device = "hostpci6"
          + id     = "0000:01:00.0"
          + pcie   = true
        }
      + hostpci {
          + device = "hostpci8"
          + id     = "0000:01:00.0"
          + pcie   = true
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.
proxmox_virtual_environment_vm.test_vm: Creating...
proxmox_virtual_environment_vm.test_vm: Creation complete after 1s [id=999]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
❯ tofu apply -auto-approve
proxmox_virtual_environment_vm.test_vm: Refreshing state... [id=999]

No changes. Your infrastructure matches the configuration.

OpenTofu has compared your real infrastructure against your configuration and found no differences, so no changes are needed.

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

Community Note

Closes #1541