From 40585d87ff30e4bfea9c4bb41dcc9747457964a4 Mon Sep 17 00:00:00 2001 From: akinross Date: Wed, 16 Oct 2024 17:24:28 +0200 Subject: [PATCH] [bugfix] Fix read and import for mso_schema_site_anp resource to select anp in correct site and template combination --- mso/resource_mso_schema_site_anp.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mso/resource_mso_schema_site_anp.go b/mso/resource_mso_schema_site_anp.go index a594b1e8..d9756ea5 100644 --- a/mso/resource_mso_schema_site_anp.go +++ b/mso/resource_mso_schema_site_anp.go @@ -68,16 +68,17 @@ func resourceMSOSchemaSiteAnpImport(d *schema.ResourceData, m interface{}) ([]*s return nil, fmt.Errorf("No Sites found") } stateSite := get_attribute[2] + stateTemplate := get_attribute[4] found := false - stateAnp := get_attribute[4] + stateAnp := get_attribute[6] for i := 0; i < count; i++ { tempCont, err := cont.ArrayElement(i, "sites") if err != nil { return nil, err } apiSite := models.StripQuotes(tempCont.S("siteId").String()) - - if apiSite == stateSite { + apiTemplate := models.StripQuotes(tempCont.S("templateName").String()) + if apiSite == stateSite && apiTemplate == stateTemplate { anpCount, err := tempCont.ArrayCount("anps") if err != nil { @@ -171,6 +172,7 @@ func resourceMSOSchemaSiteAnpRead(d *schema.ResourceData, m interface{}) error { return fmt.Errorf("No Sites found") } stateSite := d.Get("site_id").(string) + stateTemplate := d.Get("template_name").(string) found := false stateAnp := d.Get("anp_name").(string) for i := 0; i < count; i++ { @@ -179,8 +181,9 @@ func resourceMSOSchemaSiteAnpRead(d *schema.ResourceData, m interface{}) error { return err } apiSite := models.StripQuotes(tempCont.S("siteId").String()) + apiTemplate := models.StripQuotes(tempCont.S("templateName").String()) - if apiSite == stateSite { + if apiSite == stateSite && apiTemplate == stateTemplate { anpCount, err := tempCont.ArrayCount("anps") if err != nil { return fmt.Errorf("Unable to get Anp list")