Skip to content

Commit

Permalink
[minor_changes] Fix for mso_site to detect changes to a site, after m…
Browse files Browse the repository at this point in the history
…anually changing it to unmanaged and fix errorForObjectNotFound function in utils to error out when new "error" payload is found. (#231)
  • Loading branch information
anvitha-jain authored Jul 26, 2023
1 parent 4fcf175 commit 3f9fdb8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions mso/resource_mso_site.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{

Expand All @@ -79,6 +83,7 @@ func resourceMSOSite() *schema.Resource {
"urls": &schema.Schema{
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},

Expand Down
3 changes: 2 additions & 1 deletion mso/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
Expand Down

0 comments on commit 3f9fdb8

Please sign in to comment.