From 971c9b88dc7295de7e55c13d838f37c901f9435c Mon Sep 17 00:00:00 2001 From: Sabari Jaganathan <93724860+sajagana@users.noreply.github.com> Date: Thu, 18 May 2023 18:38:19 +0530 Subject: [PATCH] [ignore] added errorForObjectNotFound function to the mso util.go --- mso/resource_mso_schema.go | 7 +------ mso/util.go | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/mso/resource_mso_schema.go b/mso/resource_mso_schema.go index 9abbb5d7..4f8a7d4c 100644 --- a/mso/resource_mso_schema.go +++ b/mso/resource_mso_schema.go @@ -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())) diff --git a/mso/util.go b/mso/util.go index de123fa3..aeb7d78d 100644 --- a/mso/util.go +++ b/mso/util.go @@ -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 { @@ -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