From 96af62390a76e4d5299ec7b2a8b8b6da16fa258e Mon Sep 17 00:00:00 2001 From: Lucian Date: Wed, 7 Aug 2024 16:53:56 +0200 Subject: [PATCH 1/2] Handle 'id' for hostpci config --- proxmox/resource_vm_qemu.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/proxmox/resource_vm_qemu.go b/proxmox/resource_vm_qemu.go index 83e1250f..bc46a25e 100755 --- a/proxmox/resource_vm_qemu.go +++ b/proxmox/resource_vm_qemu.go @@ -15,13 +15,14 @@ import ( "time" pxapi "github.com/Telmate/proxmox-api-go/proxmox" - "github.com/Telmate/terraform-provider-proxmox/v2/proxmox/Internal/pxapi/guest/tags" "github.com/google/uuid" "github.com/hashicorp/go-cty/cty" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + + "github.com/Telmate/terraform-provider-proxmox/v2/proxmox/Internal/pxapi/guest/tags" ) // using a global variable here so that we have an internally accessible @@ -1526,10 +1527,14 @@ func resourceVmQemuRead(ctx context.Context, d *schema.ResourceData, meta interf d.Set("full_clone", d.Get("full_clone")) // read in the qemu hostpci - qemuPCIDevices, _ := FlattenDevicesList(config.QemuPCIDevices) + qemuPCIDevices, err := FlattenDevicesList(config.QemuPCIDevices) + if err != nil { + return diag.FromErr(fmt.Errorf("unable to flatten QEMU PCI devices: %w", err)) + } + qemuPCIDevices, _ = DropElementsFromMap([]string{"id"}, qemuPCIDevices) logger.Debug().Int("vmid", vmID).Msgf("Hostpci Block Processed '%v'", config.QemuPCIDevices) if err = d.Set("hostpci", qemuPCIDevices); err != nil { - return diag.FromErr(err) + return diag.FromErr(fmt.Errorf("unable to set hostpci: %w", err)) } // read in the qemu hostpci From 469dde147c6dc1c420880a4292f51f91a6dc1a7a Mon Sep 17 00:00:00 2001 From: Lucian Date: Mon, 12 Aug 2024 14:40:38 +0200 Subject: [PATCH 2/2] Fix VM ID overwrite --- proxmox/provider.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/proxmox/provider.go b/proxmox/provider.go index 9c50fcbd..e2dd7107 100644 --- a/proxmox/provider.go +++ b/proxmox/provider.go @@ -102,7 +102,7 @@ func Provider() *schema.Provider { "pm_tls_insecure": { Type: schema.TypeBool, Optional: true, - DefaultFunc: schema.EnvDefaultFunc("PM_TLS_INSECURE", true), //we assume it's a lab! + DefaultFunc: schema.EnvDefaultFunc("PM_TLS_INSECURE", true), // we assume it's a lab! Description: "By default, every TLS connection is verified to be secure. This option allows terraform to proceed and operate on servers considered insecure. For example if you're connecting to a remote host and you do not have the CA cert that issued the proxmox api url's certificate.", }, "pm_http_headers": { @@ -192,7 +192,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) { return nil, err } - //permission check + // permission check minimumPermissions := []string{ "Datastore.AllocateSpace", "Datastore.Audit", @@ -328,11 +328,12 @@ func getClient(pm_api_url string, func nextVmId(pconf *providerConfiguration) (nextId int, err error) { pconf.Mutex.Lock() defer pconf.Mutex.Unlock() - pconf.MaxVMID, err = pconf.Client.GetNextID(pconf.MaxVMID + 1) + nextId, err = pconf.Client.GetNextID(0) if err != nil { return 0, err } - nextId = pconf.MaxVMID + pconf.MaxVMID = nextId + return nextId, nil }