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

Patch for VM ID where a VM might be overwritten #1073

Merged
merged 4 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
"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 @@
return nil, err
}

//permission check
// permission check
minimumPermissions := []string{
"Datastore.AllocateSpace",
"Datastore.Audit",
Expand Down Expand Up @@ -270,11 +270,11 @@
return nil, err
}

func getClient(pm_api_url string,

Check failure on line 273 in proxmox/provider.go

View workflow job for this annotation

GitHub Actions / audit

don't use underscores in Go names; func parameter pm_api_url should be pmAPIURL
pm_user string,

Check failure on line 274 in proxmox/provider.go

View workflow job for this annotation

GitHub Actions / audit

don't use underscores in Go names; func parameter pm_user should be pmUser
pm_password string,

Check failure on line 275 in proxmox/provider.go

View workflow job for this annotation

GitHub Actions / audit

don't use underscores in Go names; func parameter pm_password should be pmPassword
pm_api_token_id string,

Check failure on line 276 in proxmox/provider.go

View workflow job for this annotation

GitHub Actions / audit

don't use underscores in Go names; func parameter pm_api_token_id should be pmAPITokenID
pm_api_token_secret string,

Check failure on line 277 in proxmox/provider.go

View workflow job for this annotation

GitHub Actions / audit

don't use underscores in Go names; func parameter pm_api_token_secret should be pmAPITokenSecret
pm_otp string,
pm_tls_insecure bool,
pm_http_headers string,
Expand Down Expand Up @@ -328,11 +328,12 @@
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
Loading