diff --git a/vsphere/resource_vsphere_tag.go b/vsphere/resource_vsphere_tag.go index 676523421..97b5ae1ad 100644 --- a/vsphere/resource_vsphere_tag.go +++ b/vsphere/resource_vsphere_tag.go @@ -5,6 +5,8 @@ import ( "encoding/json" "errors" "fmt" + "log" + "strings" "github.com/hashicorp/terraform/helper/schema" "github.com/vmware/vic/pkg/vsphere/tags" @@ -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) diff --git a/vsphere/resource_vsphere_tag_category.go b/vsphere/resource_vsphere_tag_category.go index 69703cb9e..f704b799c 100644 --- a/vsphere/resource_vsphere_tag_category.go +++ b/vsphere/resource_vsphere_tag_category.go @@ -4,6 +4,8 @@ import ( "context" "errors" "fmt" + "log" + "strings" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/validation" @@ -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)