Skip to content

Commit

Permalink
Merge pull request #1073 from lucian-tx/patch/vmid-overwrite
Browse files Browse the repository at this point in the history
Patch for VM ID where a VM might be overwritten
  • Loading branch information
Tinyblargon committed Aug 15, 2024
2 parents 90bf5ae + 469dde1 commit fee5edc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
9 changes: 5 additions & 4 deletions proxmox/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -192,7 +192,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
return nil, err
}

//permission check
// permission check
minimumPermissions := []string{
"Datastore.AllocateSpace",
"Datastore.Audit",
Expand Down Expand Up @@ -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
}

Expand Down
16 changes: 11 additions & 5 deletions proxmox/resource_vm_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ import (
"time"

pxapi "github.com/Telmate/proxmox-api-go/proxmox"
"github.com/Telmate/terraform-provider-proxmox/v2/proxmox/Internal/pxapi/dns/nameservers"
"github.com/Telmate/terraform-provider-proxmox/v2/proxmox/Internal/pxapi/guest/sshkeys"
"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/dns/nameservers"
"github.com/Telmate/terraform-provider-proxmox/v2/proxmox/Internal/pxapi/guest/sshkeys"
"github.com/Telmate/terraform-provider-proxmox/v2/proxmox/Internal/pxapi/guest/tags"
)

// using a global variable here so that we have an internally accessible
Expand Down Expand Up @@ -1469,10 +1471,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
Expand Down

0 comments on commit fee5edc

Please sign in to comment.