From 3ecd0443bbbdfce9bc7e8b8f082d662aac247760 Mon Sep 17 00:00:00 2001 From: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Date: Fri, 17 Jan 2025 12:40:17 -0500 Subject: [PATCH] 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> --- proxmoxtf/datasource/vms.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/proxmoxtf/datasource/vms.go b/proxmoxtf/datasource/vms.go index f22c75a4..72384356 100644 --- a/proxmoxtf/datasource/vms.go +++ b/proxmoxtf/datasource/vms.go @@ -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)...) }