mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-06-30 02:31:10 +00:00
fix(vm): do not error on read
at state refresh if VM is missing (#398)
This commit is contained in:
parent
d748a7de7b
commit
253a59ece6
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user