From 3f9fdb87ab007b200a1906f55df4a7e3c470e628 Mon Sep 17 00:00:00 2001 From: Anvitha-Jain Date: Wed, 26 Jul 2023 13:14:43 -0700 Subject: [PATCH] [minor_changes] Fix for mso_site to detect changes to a site, after manually changing it to unmanaged and fix errorForObjectNotFound function in utils to error out when new "error" payload is found. (#231) --- mso/resource_mso_site.go | 9 +++++++-- mso/util.go | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/mso/resource_mso_site.go b/mso/resource_mso_site.go index a08ea821..d6b4c921 100644 --- a/mso/resource_mso_site.go +++ b/mso/resource_mso_site.go @@ -37,11 +37,14 @@ func resourceMSOSite() *schema.Resource { "username": &schema.Schema{ Type: schema.TypeString, Optional: true, + Computed: true, }, "password": &schema.Schema{ - Type: schema.TypeString, - Optional: true, + Type: schema.TypeString, + Optional: true, + Computed: true, + Sensitive: true, }, "apic_site_id": &schema.Schema{ @@ -59,6 +62,7 @@ func resourceMSOSite() *schema.Resource { "location": &schema.Schema{ Type: schema.TypeMap, Optional: true, + // Computed: true -> Removed, as it creates discrepancy for idempotency. Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -79,6 +83,7 @@ func resourceMSOSite() *schema.Resource { "urls": &schema.Schema{ Type: schema.TypeList, Optional: true, + Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, }, diff --git a/mso/util.go b/mso/util.go index aeb7d78d..d8f93913 100644 --- a/mso/util.go +++ b/mso/util.go @@ -5,6 +5,7 @@ import ( "strings" "github.com/ciscoecosystem/mso-go-client/container" + "github.com/ciscoecosystem/mso-go-client/models" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) @@ -21,7 +22,7 @@ func toStringList(configured interface{}) []string { 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") { + if con.S("code").String() == "404" || strings.HasSuffix(err.Error(), "not found") || strings.HasSuffix(models.StripQuotes(con.S("error").String()), "no documents in result") { log.Printf("[WARN] %s, removing from state: %s", err, dn) d.SetId("") return nil