Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

185 missing site external epg docs #204

Merged
114 changes: 37 additions & 77 deletions examples/schema_site_external_epg/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,103 +14,63 @@ provider "mso" {
platform = "nd"
}

resource "mso_site" "test_site" {
name = "test_site"
username = "" # <APIC username>
password = "" # <APIC pwd>
apic_site_id = "105"
urls = "" # <APIC site url>
location = {
lat = 78.946
long = 95.623
}
data "mso_tenant" "demo_tenant" {
lhercot marked this conversation as resolved.
Show resolved Hide resolved
name = "demo_tenant"
display_name = "demo_tenant"
}

data "mso_site" "demo_site" {
name = "demo_site"
lhercot marked this conversation as resolved.
Show resolved Hide resolved
}

resource "mso_tenant" "tenant1" {
name = "test_tenant"
display_name = "test_tenant"
description = "DemoTenant"
site_associations {
site_id = mso_site.test_site.id
resource "mso_schema" "schema_blocks" {
name = "demo_schema_blocks"
template {
name = "Template1"
display_name = "Template1"
tenant_id = data.mso_tenant.demo_tenant.id
}
}

resource "mso_schema" "schema1" {
name = "test_schema"
template_name = "Template1"
tenant_id = mso_tenant.tenant1.id
resource "mso_schema_site" "demo_schema_site" {
schema_id = mso_schema.schema_blocks.id
template_name = one(mso_schema.schema_blocks.template).name
site_id = data.mso_site.demo_site.id
}

resource "mso_schema_template_vrf" "vrf1" {
schema_id = mso_schema.schema1.id
template = mso_schema.schema1.template_name
name = "vrf1"
display_name = "vrf1"
schema_id = mso_schema.schema_blocks.id
template = one(mso_schema.schema_blocks.template).name
name = "vrf1"
display_name = "vrf1"
ip_data_plane_learning = "enabled"
}

resource "mso_schema_template_l3out" "template_l3out" {
schema_id = mso_schema.schema1.id
template_name = mso_schema.schema1.template_name
schema_id = mso_schema.schema_blocks.id
template_name = one(mso_schema.schema_blocks.template).name
l3out_name = "l3out1"
display_name = "l3out1"
vrf_name = mso_schema_template_vrf.vrf1.id
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_template_external_epg" "template_externalepg" {
schema_id = mso_schema.schema1.id
template_name = mso_schema.schema1.template_name
external_epg_name = "temp_epg"
display_name = "temp_epg"
vrf_name = mso_schema_template_vrf.vrf1.id
resource "mso_schema_template_external_epg" "extepg1" {
schema_id = mso_schema.schema_blocks.id
template_name = one(mso_schema.schema_blocks.template).name
external_epg_name = "extepg1"
display_name = "extepg1"
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
l3out_name = mso_schema_template_l3out.template_l3out.l3out_name
}

resource "mso_schema_site" "schema_site_1" {
schema_id = mso_schema.schema1.id
site_id = mso_site.test_site.id
template_name = mso_schema.schema1.template_name
}

resource "mso_schema_site_vrf" "site_vrf" {
template_name = mso_schema_site.schema_site_1.template_name
site_id = mso_schema_site.schema_site_1.site_id
schema_id = mso_schema_site.schema_site_1.schema_id
vrf_name = mso_schema_template_vrf.vrf1.name
}

resource "mso_rest" "site_l3out" {
path = "/mso/api/v1/schemas/${mso_schema_site.schema_site_1.schema_id}?validate=false"
method = "PATCH"
payload = <<EOF
[
{
"op": "add",
"path": "/sites/${mso_schema_site.schema_site_1.site_id}-${mso_schema_site.schema_site_1.template_name}/intersiteL3outs/-",
"value": {
"l3outRef": {
"l3outName": "${mso_schema_template_l3out.template_l3out.l3out_name}",
"schemaId": "${mso_schema_site.schema_site_1.schema_id}",
"templateName": "${mso_schema_site.schema_site_1.template_name}"
},
"vrfRef": {
"schemaId": "${mso_schema_site_vrf.site_vrf.schema_id}",
"templateName": "${mso_schema_site_vrf.site_vrf.template_name}",
"vrfName": "${mso_schema_site_vrf.site_vrf.vrf_name}"
}
}
}
]
EOF
}

resource "mso_schema_site_external_epg" "site_externalepg" {
depends_on = [mso_rest.site_l3out]
site_id = mso_schema_site.schema_site_1.site_id
schema_id = mso_schema_site.schema_site_1.schema_id
template_name = mso_schema_template_external_epg.template_externalepg.template_name
external_epg_name = mso_schema_template_external_epg.template_externalepg.external_epg_name
resource "mso_schema_site_external_epg" "site_extepg1" {
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.extepg1.external_epg_name
l3out_name = mso_schema_template_l3out.template_l3out.l3out_name
}
57 changes: 33 additions & 24 deletions mso/datasource_mso_schema_site_external_epg.go
akinross marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,26 @@ func dataSourceMSOSchemaSiteExternalEpg() *schema.Resource {
"schema_id": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 1000),
},
"template_name": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 1000),
},
"external_epg_name": &schema.Schema{
"site_id": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 1000),
},
"l3out_name": &schema.Schema{
"external_epg_name": &schema.Schema{
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringLenBetween(1, 1000),
},
"site_id": &schema.Schema{
Type: schema.TypeList,
Optional: true,
"l3out_name": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
}),
}
Expand All @@ -67,16 +62,18 @@ func dataSourceMSOSchemaSiteExternalEpgRead(d *schema.ResourceData, m interface{
return fmt.Errorf("No Sites found")
}
stateSiteId := d.Get("site_id").(string)
stateTemplate := d.Get("template_name").(string)
found := false
stateExternalEpg := d.Get("external_epg_name").(string)
for i := 0; i < count; i++ {
for i := 0; i < count && !found; i++ {
siteCont, err := cont.ArrayElement(i, "sites")
if err != nil {
return err
}
apiSiteId := models.StripQuotes(siteCont.S("siteId").String())

if apiSiteId == stateSiteId {
apiTemplate := models.StripQuotes(siteCont.S("templateName").String())
akinross marked this conversation as resolved.
Show resolved Hide resolved
if apiSiteId == stateSiteId && apiTemplate == stateTemplate {
externalEpgCount, err := siteCont.ArrayCount("externalEpgs")
if err != nil {
return fmt.Errorf("Unable to get External EPG list")
Expand All @@ -87,22 +84,34 @@ func dataSourceMSOSchemaSiteExternalEpgRead(d *schema.ResourceData, m interface{
return err
}
externalEpgRef := models.StripQuotes(externalEpgCont.S("externalEpgRef").String())
re := regexp.MustCompile("/schemas/(.*)/templates/(.*)/externalEpgs/(.*)")
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)
log.Printf("[TRACE] resourceMSOSchemaSiteExternalEpgRead externalEpgRef: %s match: %s", externalEpgRef, match)
anvitha-jain marked this conversation as resolved.
Show resolved Hide resolved
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())
reL3out := regexp.MustCompile("/schemas/(.*)/templates/(.*)/l3outs/(.*)")
matchL3out := reL3out.FindStringSubmatch(l3outRef)
d.Set("l3out_name", matchL3out[3])
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
6 changes: 3 additions & 3 deletions mso/resource_mso_rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ func resourceMSORestDelete(d *schema.ResourceData, m interface{}) error {
var method, path, payload string
path = d.Get("path").(string)
payload = d.Get("payload").(string)
if tempVar, ok := d.GetOk("method"); !ok {

if _, ok := d.GetOk("method"); !ok {
method = "DELETE"
msoClient := m.(*client.Client)
_, err := MakeRestRequest(msoClient, path, method, payload)

if err != nil {
return err
}
Expand Down
48 changes: 30 additions & 18 deletions mso/resource_mso_schema_site_external_epg.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func resourceMSOSchemaSiteExternalEpgImport(d *schema.ResourceData, m interface{
stateSiteId := get_attribute[2]
found := false
stateExternalEpg := get_attribute[4]
for i := 0; i < count; i++ {
for i := 0; i < count && !found; i++ {
siteCont, err := cont.ArrayElement(i, "sites")
if err != nil {
return nil, err
Expand All @@ -86,30 +86,42 @@ func resourceMSOSchemaSiteExternalEpgImport(d *schema.ResourceData, m interface{
if apiSiteId == stateSiteId {
externalEpgCount, err := siteCont.ArrayCount("externalEpgs")
if err != nil {
return nil, fmt.Errorf("Unable to get Externalepg list")
return nil, fmt.Errorf("Unable to get External EPG list")
}
for j := 0; j < externalEpgCount; j++ {
externalEpgCont, err := siteCont.ArrayElement(j, "externalEpgs")
if err != nil {
return nil, err
}
externalEpgRef := models.StripQuotes(externalEpgCont.S("externalEpgRef").String())
re := regexp.MustCompile("/schemas/(.*)/templates/(.*)/externalEpgs/(.*)")
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())
reL3out := regexp.MustCompile("/schemas/(.*)/templates/(.*)/l3outs/(.*)")
matchL3out := reL3out.FindStringSubmatch(l3outRef)
d.Set("l3out_name", matchL3out[3])

found = true
break
log.Printf("[TRACE] resourceMSOSchemaSiteExternalEpgRead externalEpgRef: %s match: %s", externalEpgRef, match)
akinross marked this conversation as resolved.
Show resolved Hide resolved
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 nil, fmt.Errorf("Error in parsing l3outRef to get L3Out name")
}
}

found = true
break
}
} else {
return nil, fmt.Errorf("Error in parsing externalEpgRef to get External EPG name")
}
}
}
Expand Down Expand Up @@ -206,7 +218,7 @@ func resourceMSOSchemaSiteExternalEpgRead(d *schema.ResourceData, m interface{})
stateSiteId := d.Get("site_id").(string)
found := false
stateExternalEpg := d.Get("external_epg_name").(string)
for i := 0; i < count; i++ {
for i := 0; i < count && !found; i++ {
siteCont, err := cont.ArrayElement(i, "sites")
if err != nil {
return err
Expand Down
33 changes: 33 additions & 0 deletions website/docs/d/schema_site_external_epg.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
layout: "mso"
page_title: "MSO: mso_schema_site_external_epg"
sidebar_current: "docs-mso-data-source-schema_site_external_epg"
description: |-
Data source for MSO Schema Site External Endpoint Groups.
---

# mso_schema_site_external_epg #

Data source for MSO Schema Site External Endpoint Groups.

```hcl

data "mso_schema_site_external_epg" "external_epg_1" {
schema_id = data.mso_schema.schema1.id
template_name = "Template1"
site_id = data.mso_site.site1.id
external_epg_name = "external_epg_1"
}

```

## Argument Reference ##

* `schema_id` - (Required) Schema ID under which you want to deploy the External Endpoint Group.
* `site_id` - (Required) Site ID under which you want to deploy the External Endpoint Group.
* `template_name` - (Required) Template Name under which you want to define the External Endpoint Group.
* `external_epg_name` - (Required) Name of the External Endpoint Group.

## Attribute Reference ##

* `l3out_name` - (Read-Only) Name of the L3Out.
Loading