From 5720d5955843ffedb416a764eb04aca6d33f0c77 Mon Sep 17 00:00:00 2001 From: Enhao Cui Date: Mon, 28 Feb 2022 15:23:08 -0800 Subject: [PATCH] Fix VM Not Found Issue in VM Tag Fix for issue #709. In such cases, provider should just swallow the error, and print error messages. Signed-off-by: Enhao Cui --- nsxt/resource_nsxt_policy_vm_tags.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/nsxt/resource_nsxt_policy_vm_tags.go b/nsxt/resource_nsxt_policy_vm_tags.go index 1cf6a4a00..9aa4aeba4 100644 --- a/nsxt/resource_nsxt_policy_vm_tags.go +++ b/nsxt/resource_nsxt_policy_vm_tags.go @@ -305,7 +305,8 @@ func resourceNsxtPolicyVMTagsRead(d *schema.ResourceData, m interface{}) error { vm, err := findNsxtPolicyVMByID(connector, vmID, m) if err != nil { - return fmt.Errorf("Error during Virtual Machine retrieval: %v", err) + log.Printf("[ERROR] Cannot find VM with ID %s, skip reading VM tag", vmID) + return nil } setPolicyTagsInSchema(d, vm.Tags) @@ -324,7 +325,8 @@ func resourceNsxtPolicyVMTagsCreate(d *schema.ResourceData, m interface{}) error vm, err := findNsxtPolicyVMByID(connector, instanceID, m) if err != nil { - return fmt.Errorf("Error finding Virtual Machine: %v", err) + log.Printf("[ERROR] Cannot find VM with ID %s, skip creating/updating VM Tag", instanceID) + return nil } tags := getPolicyTagsFromSchema(d) @@ -358,8 +360,10 @@ func resourceNsxtPolicyVMTagsDelete(d *schema.ResourceData, m interface{}) error instanceID := d.Get("instance_id").(string) vm, err := findNsxtPolicyVMByID(connector, instanceID, m) + if err != nil { - return fmt.Errorf("Error finding Virtual Machine: %v", err) + log.Printf("[ERROR] Cannot find VM with ID %s, deleting stale VM Tag on provider", instanceID) + return nil } tags := make([]model.Tag, 0)