Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix VM Not Found Issue in VM Tag #718

Merged
merged 1 commit into from
Mar 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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", vmID)
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