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

r/tag: Remove deleted tags #801

Merged
merged 1 commit into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion vsphere/resource_vsphere_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"strings"

"github.com/hashicorp/terraform/helper/schema"
"github.com/vmware/vic/pkg/vsphere/tags"
Expand Down Expand Up @@ -79,7 +81,12 @@ func resourceVSphereTagRead(d *schema.ResourceData, meta interface{}) error {
defer cancel()
tag, err := client.GetTag(ctx, id)
if err != nil {
return fmt.Errorf("could not locate tag with id %q: %s", id, err)
if strings.Contains(err.Error(), "com.vmware.vapi.std.errors.not_found") {
log.Printf("[DEBUG] Tag %s: Resource has been deleted", id)
d.SetId("")
return nil
}
return err
}
d.Set("name", tag.Name)
d.Set("description", tag.Description)
Expand Down
9 changes: 8 additions & 1 deletion vsphere/resource_vsphere_tag_category.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"errors"
"fmt"
"log"
"strings"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
Expand Down Expand Up @@ -104,7 +106,12 @@ func resourceVSphereTagCategoryRead(d *schema.ResourceData, meta interface{}) er
defer cancel()
category, err := client.GetCategory(ctx, id)
if err != nil {
return fmt.Errorf("could not locate category with id %q: %s", id, err)
if strings.Contains(err.Error(), "com.vmware.vapi.std.errors.not_found") {
log.Printf("[DEBUG] Tag category %s: Resource has been deleted", id)
d.SetId("")
return nil
}
return err
}
d.Set("name", category.Name)
d.Set("description", category.Description)
Expand Down