Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions examples/schema_site_external_epg/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,22 @@ resource "mso_schema_site_external_epg" "site_extepg1" {
external_epg_name = mso_schema_template_external_epg.extepg1.external_epg_name
l3out_name = mso_schema_template_l3out.template_l3out.l3out_name
}

resource "mso_schema_template_external_epg" "extepg2" {
schema_id = mso_schema.schema_blocks.id
template_name = one(mso_schema.schema_blocks.template).name
external_epg_name = "extepg2"
display_name = "extepg2"
vrf_name = mso_schema_template_vrf.vrf1.name
vrf_schema_id = mso_schema_template_vrf.vrf1.schema_id
vrf_template_name = mso_schema_template_vrf.vrf1.template
}

resource "mso_schema_site_external_epg" "site_extepg2" {
site_id = mso_schema_site.demo_schema_site.id
schema_id = mso_schema.schema_blocks.id
template_name = one(mso_schema.schema_blocks.template).name
external_epg_name = mso_schema_template_external_epg.extepg2.external_epg_name
l3out_name = "L3out2"
l3out_on_apic = true
}
79 changes: 70 additions & 9 deletions mso/resource_mso_schema_site_external_epg.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,23 @@ func resourceMSOSchemaSiteExternalEpg() *schema.Resource {
Computed: true,
ValidateFunc: validation.StringLenBetween(1, 1000),
},
"l3out_template_name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringLenBetween(1, 1000),
},
"l3out_schema_id": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringLenBetween(1, 1000),
},
"l3out_on_apic": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Default: false,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a default here? Is not providing it not the same as false. In documentation we should mention the default.

},
}),
}
}
Expand Down Expand Up @@ -106,15 +123,29 @@ func resourceMSOSchemaSiteExternalEpgImport(d *schema.ResourceData, m interface{
d.Set("site_id", apiSiteId)

l3outRef := models.StripQuotes(externalEpgCont.S("l3outRef").String())
l3outDn := models.StripQuotes(externalEpgCont.S("l3outDn").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])
d.Set("l3out_schema_id", matchL3out[1])
d.Set("l3out_template_name", matchL3out[2])
d.Set("l3out_on_apic", false)
} else {
return nil, fmt.Errorf("Error in parsing l3outRef to get L3Out name")
}
} else if l3outDn != "{}" && l3outDn != "" {
reL3out := regexp.MustCompile("uni/tn-(.*?)/out-(.*)")
matchL3out := reL3out.FindStringSubmatch(l3outDn)
log.Printf("[TRACE] resourceMSOSchemaSiteExternalEpgRead l3outDn: %s matchL3out: %s", l3outDn, matchL3out)
if len(matchL3out) >= 2 {
d.Set("l3out_name", matchL3out[1])
d.Set("l3out_on_apic", true)
} else {
return fmt.Errorf("Error in parsing l3outDn to get L3Out name")
}
}

found = true
Expand Down Expand Up @@ -147,6 +178,9 @@ func resourceMSOSchemaSiteExternalEpgCreate(d *schema.ResourceData, m interface{
externalEpgName := d.Get("external_epg_name").(string)
templateName := d.Get("template_name").(string)
l3outName := d.Get("l3out_name").(string)
l3outTemplate := d.Get("l3out_template_name").(string)
l3outSchema := d.Get("l3out_schema_id").(string)
l3outOnApic := d.Get("l3out_on_apic").(bool)

siteEpgMap := make(map[string]interface{})

Expand All @@ -156,14 +190,19 @@ func resourceMSOSchemaSiteExternalEpgCreate(d *schema.ResourceData, m interface{
if err != nil {
return err
}

l3outRefMap := make(map[string]interface{})

l3outRefMap["schemaId"] = schemaId
l3outRefMap["templateName"] = templateName
l3outRefMap["l3outName"] = l3outName
if l3outOnApic {
siteEpgMap["l3outRef"] = ""
} else {
l3outRefMap["schemaId"] = l3outSchema
l3outRefMap["templateName"] = l3outTemplate
l3outRefMap["l3outName"] = l3outName
Copy link
Collaborator

@akinross akinross Aug 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking we still miss a thing. We can do two things actually.

  • We should do a check that the template and schema are provided because they are optional but I believe they are required for the ref to be constructed.
  • Or we can set the schema/template of the external epg when these are not provided. ( my preference )

Another thing is should we add validation of config to make l3outSchema/l3outTemplate mutually exclusive from l3out_on_apic?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behaviour should also be described in documentation.


siteEpgMap["l3outRef"] = l3outRefMap
siteEpgMap["l3outRef"] = l3outRefMap
}

siteEpgMap["l3outDn"] = fmt.Sprintf("uni/tn-%s/out-%s", tenantName, l3outName)
} else {
siteEpgMap["l3outDn"] = ""
Expand Down Expand Up @@ -248,15 +287,29 @@ func resourceMSOSchemaSiteExternalEpgRead(d *schema.ResourceData, m interface{})
d.Set("site_id", apiSiteId)

l3outRef := models.StripQuotes(externalEpgCont.S("l3outRef").String())
l3outDn := models.StripQuotes(externalEpgCont.S("l3outDn").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])
d.Set("l3out_schema_id", matchL3out[1])
d.Set("l3out_template_name", matchL3out[2])
d.Set("l3out_on_apic", false)
} else {
return fmt.Errorf("Error in parsing l3outRef to get L3Out name")
}
} else if l3outDn != "{}" && l3outDn != "" {
reL3out := regexp.MustCompile("uni/tn-(.*?)/out-(.*)")
matchL3out := reL3out.FindStringSubmatch(l3outDn)
log.Printf("[TRACE] resourceMSOSchemaSiteExternalEpgRead l3outDn: %s matchL3out: %s", l3outDn, matchL3out)
if len(matchL3out) >= 2 {
d.Set("l3out_name", matchL3out[1])
d.Set("l3out_on_apic", true)
} else {
return fmt.Errorf("Error in parsing l3outDn to get L3Out name")
}
}

found = true
Expand Down Expand Up @@ -287,6 +340,9 @@ func resourceMSOSchemaSiteExternalEpgUpdate(d *schema.ResourceData, m interface{
templateName := d.Get("template_name").(string)
externalEpgName := d.Get("external_epg_name").(string)
l3outName := d.Get("l3out_name").(string)
l3outTemplate := d.Get("l3out_template_name").(string)
l3outSchema := d.Get("l3out_schema_id").(string)
l3outOnApic := d.Get("l3out_on_apic").(bool)

siteEpgMap := make(map[string]interface{})

Expand All @@ -299,11 +355,16 @@ func resourceMSOSchemaSiteExternalEpgUpdate(d *schema.ResourceData, m interface{

l3outRefMap := make(map[string]interface{})

l3outRefMap["schemaId"] = schemaId
l3outRefMap["templateName"] = templateName
l3outRefMap["l3outName"] = l3outName
if l3outOnApic {
siteEpgMap["l3outRef"] = ""
} else {

l3outRefMap["schemaId"] = l3outSchema
l3outRefMap["templateName"] = l3outTemplate
l3outRefMap["l3outName"] = l3outName

siteEpgMap["l3outRef"] = l3outRefMap
siteEpgMap["l3outRef"] = l3outRefMap
}
siteEpgMap["l3outDn"] = fmt.Sprintf("uni/tn-%s/out-%s", tenantName, l3outName)
} else {
siteEpgMap["l3outDn"] = ""
Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/schema_site_external_epg.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ resource "mso_schema_site_external_epg" "external_epg_1" {
## Attribute Reference ##

* `l3out_name` - (Optional) Name of the L3Out.
* `l3out_schema_id` - (Optional) Schema ID of the L3Out.
* `l3out_template_name` - (Optional) Template of the L3Out.
* `l3out_on_apic` - (Optional) Whether L3Out is created only locally on APIC.

## Importing ##

Expand Down