Skip to content

Commit

Permalink
Fix API change in l3outRef and add some error catching conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
lhercot committed Dec 15, 2021
1 parent c5657be commit 131f729
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions mso/resource_mso_schema_site_external_epg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}
Expand Down

0 comments on commit 131f729

Please sign in to comment.