mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-01 02:52:58 +00:00
fix(vm): handle PVE node availability in VM datasource (#1715)
- Added error handling for HTTP error code 595 in vmsRead, providing a warning if a node is not available, which may result in an incomplete VM list. Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
parent
eccd55f522
commit
3ecd0443bb
@ -8,6 +8,7 @@ package datasource
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"slices"
|
||||
@ -20,6 +21,7 @@ import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
|
||||
"github.com/bpg/terraform-provider-proxmox/proxmox"
|
||||
proxmoxapi "github.com/bpg/terraform-provider-proxmox/proxmox/api"
|
||||
"github.com/bpg/terraform-provider-proxmox/proxmox/types"
|
||||
"github.com/bpg/terraform-provider-proxmox/proxmoxtf"
|
||||
)
|
||||
@ -86,7 +88,7 @@ func VMs() *schema.Resource {
|
||||
}
|
||||
}
|
||||
|
||||
// vmRead reads the data of a VM by ID.
|
||||
// vmRead reads the VMs.
|
||||
func vmsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
var diags diag.Diagnostics
|
||||
|
||||
@ -121,6 +123,16 @@ func vmsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Di
|
||||
for _, nodeName := range nodeNames {
|
||||
listData, e := api.Node(nodeName).VM(0).ListVMs(ctx)
|
||||
if e != nil {
|
||||
var httpError *proxmoxapi.HTTPError
|
||||
if errors.As(e, &httpError) && httpError.Code == 595 {
|
||||
diags = append(diags, diag.Diagnostic{
|
||||
Severity: diag.Warning,
|
||||
Summary: fmt.Sprintf("node %q is not available - VM list may be incomplete", nodeName),
|
||||
})
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
diags = append(diags, diag.FromErr(e)...)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user