Skip to content

Commit

Permalink
[ignore] added errorForObjectNotFound function to the mso util.go
Browse files Browse the repository at this point in the history
  • Loading branch information
sajagana authored and lhercot committed May 24, 2023
1 parent 505f04d commit 971c9b8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
7 changes: 1 addition & 6 deletions mso/resource_mso_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,7 @@ func resourceMSOSchemaRead(d *schema.ResourceData, m interface{}) error {
dn := d.Id()
con, err := msoClient.GetViaURL(fmt.Sprintf("api/v1/schemas/" + dn))
if err != nil {
if con.S("code").String() == "404" {
d.SetId("")
return nil
} else {
return err
}
return errorForObjectNotFound(err, dn, con, d)
}

d.SetId(models.StripQuotes(con.S("id").String()))
Expand Down
21 changes: 21 additions & 0 deletions mso/util.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package mso

import (
"log"
"strings"

"github.com/ciscoecosystem/mso-go-client/container"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

const version = 1

func toStringList(configured interface{}) []string {
Expand All @@ -11,4 +19,17 @@ func toStringList(configured interface{}) []string {
return vs
}

func errorForObjectNotFound(err error, dn string, con *container.Container, d *schema.ResourceData) error {
if err != nil {
if con.S("code").String() == "404" || strings.HasSuffix(err.Error(), "not found") {
log.Printf("[WARN] %s, removing from state: %s", err, dn)
d.SetId("")
return nil
} else {
return err
}
}
return nil
}

// CHANGE TO UTILS IF YOU ADD MORE FUNCTIONS

0 comments on commit 971c9b8

Please sign in to comment.