Skip to content

Commit

Permalink
Fix VM Not Found Issue in VM Tag
Browse files Browse the repository at this point in the history
Fix for issue #709. In such cases, provider should just swallow
the error, and print error messages.
  • Loading branch information
Enhao Cui committed Feb 28, 2022
1 parent 7feb1ae commit 7d13ab6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions nsxt/resource_nsxt_policy_vm_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", instanceID)
return nil
}

setPolicyTagsInSchema(d, vm.Tags)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7d13ab6

Please sign in to comment.