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

Modified code to incorporate changes made in NDO version >= 4.2's API response for 'regions' #254

Merged
merged 4 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
39 changes: 27 additions & 12 deletions mso/datasource_mso_schema_site_vrf_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,27 +147,42 @@ func dataSourceMSOSchemaSiteVrfRegionRead(d *schema.ResourceData, m interface{})
d.Set("region_name", region)
}

if regionCont.Exists("isVpnGatewayRouter") {
d.Set("vpn_gateway", regionCont.S("isVpnGatewayRouter").Data().(bool))
}
if regionCont.Exists("isTGWAttachment") {
d.Set("hub_network_enable", regionCont.S("isTGWAttachment").Data().(bool))
var cidrs []interface{}
var regionOrVpcsContainer map[string]interface{}
if regionCont.Exists("vpcs") {
vpcsInterface := regionCont.S("vpcs").Data()
vpcs := vpcsInterface.([]interface{})
if len(vpcs) > 0 {
regionOrVpcsContainer = vpcs[0].(map[string]interface{})
if cidrsInterface, exists := regionOrVpcsContainer["cidrs"]; exists {
cidrs = cidrsInterface.([]interface{})
}
}
} else {
regionOrVpcsContainer = regionCont.Data().(map[string]interface{})
if regionCont.Exists("cidrs") {
cidrsData := regionCont.S("cidrs").Data()
if cidrsData != nil {
cidrs = cidrsData.([]interface{})
}
}
}

if isVpnGatewayRouter, exists := regionOrVpcsContainer["isVpnGatewayRouter"]; exists {
d.Set("vpn_gateway", isVpnGatewayRouter)
}
if isTGWAttachment, exists := regionOrVpcsContainer["isTGWAttachment"]; exists {
d.Set("hub_network_enable", isTGWAttachment)
}
hubMap := make(map[string]interface{})
if regionCont.Exists("cloudRsCtxProfileToGatewayRouterP") {
temp := regionCont.S("cloudRsCtxProfileToGatewayRouterP").Data().(map[string]interface{})

if cloudRsCtxProfileToGatewayRouterP, exists := regionOrVpcsContainer["cloudRsCtxProfileToGatewayRouterP"]; exists {
temp := cloudRsCtxProfileToGatewayRouterP.(map[string]interface{})
hubMap["name"] = temp["name"]
hubMap["tenant_name"] = temp["tenantName"]

d.Set("hub_network", hubMap)
} else {
d.Set("hub_network", hubMap)
}

cidrList := make([]interface{}, 0, 1)
cidrs := regionCont.S("cidrs").Data().([]interface{})
for _, tempCidr := range cidrs {
cidr := tempCidr.(map[string]interface{})

Expand Down
5 changes: 4 additions & 1 deletion mso/datasource_mso_tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ func datasourceMSOTenantRead(d *schema.ResourceData, m interface{}) error {
readAzureAccountDataFromSchema(sitesCont, mapSite)

if sitesCont.Exists("cloudAccount") && sitesCont.S("cloudAccount").String() != "{}" {
setCloudAccountInfo(strings.Split(sitesCont.S("cloudAccount").String(), "/")[2], mapSite)
splitStr := strings.Split(sitesCont.S("cloudAccount").String(), "/")
if len(splitStr) > 2 {
setCloudAccountInfo(splitStr[2], mapSite)
}
}

site_associations = append(site_associations, mapSite)
Expand Down
97 changes: 70 additions & 27 deletions mso/resource_mso_schema_site_vrf_region.go
shrsr marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ func resourceMSOSchemaSiteVrfRegion() *schema.Resource {
},
"cidr": &schema.Schema{
Type: schema.TypeList,
Required: true,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cidr_ip": &schema.Schema{
Expand Down Expand Up @@ -139,6 +140,15 @@ func resourceMSOSchemaSiteVrfRegion() *schema.Resource {
},
},
}),
CustomizeDiff: func(diff *schema.ResourceDiff, v interface{}) error {
configOld, configNew := diff.GetChange("hub_network")
stateHub := configOld.(map[string]interface{})
configHub := configNew.(map[string]interface{})
if len(stateHub) == 0 && len(configHub) == 0 {
diff.Clear("hub_network")
}
return nil
},
}
}

Expand Down Expand Up @@ -200,29 +210,44 @@ func resourceMSOSchemaSiteVrfRegionImport(d *schema.ResourceData, m interface{})
}
apiRegion := models.StripQuotes(regionCont.S("name").String())
if apiRegion == stateRegion {
d.SetId(apiRegion)
d.SetId(d.Id())
d.Set("region_name", apiRegion)
if regionCont.Exists("isVpnGatewayRouter") {
d.Set("vpn_gateway", regionCont.S("isVpnGatewayRouter").Data().(bool))
}
if regionCont.Exists("isTGWAttachment") {
d.Set("hub_network_enable", regionCont.S("isTGWAttachment").Data().(bool))
var cidrs []interface{}
var regionOrVpcsContainer map[string]interface{}
if regionCont.Exists("vpcs") {
vpcsInterface := regionCont.S("vpcs").Data()
vpcs := vpcsInterface.([]interface{})
if len(vpcs) > 0 {
regionOrVpcsContainer = vpcs[0].(map[string]interface{})
if cidrsInterface, exists := regionOrVpcsContainer["cidrs"]; exists {
cidrs = cidrsInterface.([]interface{})
}
}
} else {
regionOrVpcsContainer = regionCont.Data().(map[string]interface{})
if regionCont.Exists("cidrs") {
cidrsData := regionCont.S("cidrs").Data()
if cidrsData != nil {
cidrs = cidrsData.([]interface{})
}
}
}

if isVpnGatewayRouter, exists := regionOrVpcsContainer["isVpnGatewayRouter"]; exists {
d.Set("vpn_gateway", isVpnGatewayRouter)
}
if isTGWAttachment, exists := regionOrVpcsContainer["isTGWAttachment"]; exists {
d.Set("hub_network_enable", isTGWAttachment)
}
hubMap := make(map[string]interface{})
if regionCont.Exists("cloudRsCtxProfileToGatewayRouterP") {
temp := regionCont.S("cloudRsCtxProfileToGatewayRouterP").Data().(map[string]interface{})

if cloudRsCtxProfileToGatewayRouterP, exists := regionOrVpcsContainer["cloudRsCtxProfileToGatewayRouterP"]; exists {
temp := cloudRsCtxProfileToGatewayRouterP.(map[string]interface{})
hubMap["name"] = temp["name"]
hubMap["tenant_name"] = temp["tenantName"]

d.Set("hub_network", hubMap)
} else {
d.Set("hub_network", hubMap)
}

cidrList := make([]interface{}, 0, 1)
cidrs := regionCont.S("cidrs").Data().([]interface{})
for _, tempCidr := range cidrs {
cidr := tempCidr.(map[string]interface{})

Expand Down Expand Up @@ -463,6 +488,7 @@ func resourceMSOSchemaSiteVrfRegionRead(d *schema.ResourceData, m interface{}) e
}

stateSite := d.Get("site_id").(string)
stateTemplate := d.Get("template_name").(string)
found := false
stateVrf := d.Get("vrf_name").(string)
stateRegion := d.Get("region_name").(string)
Expand All @@ -473,8 +499,9 @@ func resourceMSOSchemaSiteVrfRegionRead(d *schema.ResourceData, m interface{}) e
return err
}
apiSite := models.StripQuotes(tempCont.S("siteId").String())
apiTemplate := models.StripQuotes(tempCont.S("templateName").String())

if apiSite == stateSite {
if apiSite == stateSite && apiTemplate == stateTemplate {
vrfCount, err := tempCont.ArrayCount("vrfs")
if err != nil {
return fmt.Errorf("Unable to get Vrf list")
Expand Down Expand Up @@ -503,29 +530,45 @@ func resourceMSOSchemaSiteVrfRegionRead(d *schema.ResourceData, m interface{}) e
}
apiRegion := models.StripQuotes(regionCont.S("name").String())
if apiRegion == stateRegion {
d.SetId(apiRegion)
d.SetId(fmt.Sprintf("%s/sites/%s/template/%s/vrf/%s/region/%s", schemaId, stateSite, stateTemplate, stateVrf, stateRegion))
shrsr marked this conversation as resolved.
Show resolved Hide resolved
d.Set("region_name", apiRegion)
if regionCont.Exists("isVpnGatewayRouter") {
d.Set("vpn_gateway", regionCont.S("isVpnGatewayRouter").Data().(bool))
var cidrs []interface{}
var regionOrVpcsContainer map[string]interface{}
if regionCont.Exists("vpcs") {
vpcsInterface := regionCont.S("vpcs").Data()
vpcs := vpcsInterface.([]interface{})
if len(vpcs) > 0 {
regionOrVpcsContainer = vpcs[0].(map[string]interface{})
if cidrsInterface, exists := regionOrVpcsContainer["cidrs"]; exists {
cidrs = cidrsInterface.([]interface{})
}
}
} else {
regionOrVpcsContainer = regionCont.Data().(map[string]interface{})
if regionCont.Exists("cidrs") {
cidrsData := regionCont.S("cidrs").Data()
if cidrsData != nil {
cidrs = cidrsData.([]interface{})
}
}
}

if isVpnGatewayRouter, exists := regionOrVpcsContainer["isVpnGatewayRouter"]; exists {
d.Set("vpn_gateway", isVpnGatewayRouter)
}
if regionCont.Exists("isTGWAttachment") {
d.Set("hub_network_enable", regionCont.S("isTGWAttachment").Data().(bool))
if isTGWAttachment, exists := regionOrVpcsContainer["isTGWAttachment"]; exists {
d.Set("hub_network_enable", isTGWAttachment)
}

hubMap := make(map[string]interface{})
if regionCont.Exists("cloudRsCtxProfileToGatewayRouterP") {
temp := regionCont.S("cloudRsCtxProfileToGatewayRouterP").Data().(map[string]interface{})

if cloudRsCtxProfileToGatewayRouterP, exists := regionOrVpcsContainer["cloudRsCtxProfileToGatewayRouterP"]; exists {
temp := cloudRsCtxProfileToGatewayRouterP.(map[string]interface{})
hubMap["name"] = temp["name"]
hubMap["tenant_name"] = temp["tenantName"]

d.Set("hub_network", hubMap)
} else {
d.Set("hub_network", hubMap)
}

cidrList := make([]interface{}, 0, 1)
cidrs := regionCont.S("cidrs").Data().([]interface{})
for _, tempCidr := range cidrs {
cidr := tempCidr.(map[string]interface{})

Expand Down
10 changes: 8 additions & 2 deletions mso/resource_mso_tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,10 @@ func resourceMSOTenantImport(d *schema.ResourceData, m interface{}) ([]*schema.R
readAzureAccountDataFromSchema(sitesCont, mapSite)

if sitesCont.Exists("cloudAccount") && sitesCont.S("cloudAccount").String() != "{}" {
setCloudAccountInfo(strings.Split(sitesCont.S("cloudAccount").String(), "/")[2], mapSite)
splitStr := strings.Split(sitesCont.S("cloudAccount").String(), "/")
if len(splitStr) > 2 {
setCloudAccountInfo(splitStr[2], mapSite)
}
}

site_associations = append(site_associations, mapSite)
Expand Down Expand Up @@ -794,7 +797,10 @@ func resourceMSOTenantRead(d *schema.ResourceData, m interface{}) error {
readAzureAccountDataFromSchema(sitesCont, mapSite)

if sitesCont.Exists("cloudAccount") && sitesCont.S("cloudAccount").String() != "{}" {
setCloudAccountInfo(strings.Split(sitesCont.S("cloudAccount").String(), "/")[2], mapSite)
splitStr := strings.Split(sitesCont.S("cloudAccount").String(), "/")
if len(splitStr) > 2 {
setCloudAccountInfo(splitStr[2], mapSite)
}
}

site_associations = append(site_associations, mapSite)
Expand Down