0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-06-30 10:33:46 +00:00

fix(vm): do not error on read at state refresh if VM is missing (#398)

This commit is contained in:
Pavel Boldyrev 2023-07-02 20:48:38 -04:00 committed by GitHub
parent d748a7de7b
commit 253a59ece6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -22,6 +22,9 @@ const (
getVMIDStep = 1
)
// ErrVMDoesNotExist is returned when the VM identifier cannot be found on any cluster node.
var ErrVMDoesNotExist = errors.New("unable to find VM identifier on any cluster node")
var (
//nolint:gochecknoglobals
getVMIDCounter = -1
@ -136,5 +139,5 @@ func (c *Client) GetVMNodeName(ctx context.Context, vmID int) (*string, error) {
}
}
return nil, errors.New("unable to determine node name for VM identifier")
return nil, ErrVMDoesNotExist
}

View File

@ -21,6 +21,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
types2 "github.com/bpg/terraform-provider-proxmox/internal/types"
"github.com/bpg/terraform-provider-proxmox/proxmox/cluster"
"github.com/bpg/terraform-provider-proxmox/proxmox/nodes/vms"
"github.com/bpg/terraform-provider-proxmox/proxmox/types"
"github.com/bpg/terraform-provider-proxmox/proxmoxtf"
@ -3042,6 +3043,12 @@ func vmRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Dia
vmNodeName, err := api.Cluster().GetVMNodeName(ctx, vmID)
if err != nil {
if errors.Is(err, cluster.ErrVMDoesNotExist) {
d.SetId("")
return nil
}
return diag.FromErr(err)
}