From 131f72952b884839d59eff23fab4ee6cfac3c52d Mon Sep 17 00:00:00 2001 From: Lionel Hercot Date: Thu, 16 Dec 2021 00:47:00 +0100 Subject: [PATCH] Fix API change in l3outRef and add some error catching conditions --- mso/resource_mso_schema_site_external_epg.go | 40 ++++++++++++-------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/mso/resource_mso_schema_site_external_epg.go b/mso/resource_mso_schema_site_external_epg.go index 1ae2c096..71b918bc 100644 --- a/mso/resource_mso_schema_site_external_epg.go +++ b/mso/resource_mso_schema_site_external_epg.go @@ -214,22 +214,32 @@ func resourceMSOSchemaSiteExternalEpgRead(d *schema.ResourceData, m interface{}) externalEpgRef := models.StripQuotes(externalEpgCont.S("externalEpgRef").String()) re := regexp.MustCompile("/schemas/(.*?)/templates/(.*?)/externalEpgs/(.*)") match := re.FindStringSubmatch(externalEpgRef) - if match[3] == stateExternalEpg { - d.SetId(match[3]) - d.Set("external_epg_name", match[3]) - d.Set("schema_id", match[1]) - d.Set("template_name", match[2]) - d.Set("site_id", apiSiteId) - - l3outRef := models.StripQuotes(externalEpgCont.S("l3outRef").String()) - if l3outRef != "{}" { - reL3out := regexp.MustCompile("/schemas/(.*?)/templates/(.*?)/l3outs/(.*)") - matchL3out := reL3out.FindStringSubmatch(l3outRef) - d.Set("l3out_name", matchL3out[3]) + log.Printf("[TRACE] resourceMSOSchemaSiteExternalEpgRead externalEpgRef: %s match: %s", externalEpgRef, match) + if len(match) >= 4 { + if match[3] == stateExternalEpg { + d.SetId(match[3]) + d.Set("external_epg_name", match[3]) + d.Set("schema_id", match[1]) + d.Set("template_name", match[2]) + d.Set("site_id", apiSiteId) + + l3outRef := models.StripQuotes(externalEpgCont.S("l3outRef").String()) + if l3outRef != "{}" && l3outRef != "" { + reL3out := regexp.MustCompile("/schemas/(.*?)/templates/(.*?)/l3outs/(.*)") + matchL3out := reL3out.FindStringSubmatch(l3outRef) + log.Printf("[TRACE] resourceMSOSchemaSiteExternalEpgRead l3outRef: %s matchL3out: %s", l3outRef, matchL3out) + if len(matchL3out) >= 4 { + d.Set("l3out_name", matchL3out[3]) + } else { + return fmt.Errorf("Error in parsing l3outRef to get L3Out name") + } + } + + found = true + break } - - found = true - break + } else { + return fmt.Errorf("Error in parsing externalEpgRef to get External EPG name") } } }