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 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
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
81 changes: 56 additions & 25 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 @@ -202,27 +203,42 @@ func resourceMSOSchemaSiteVrfRegionImport(d *schema.ResourceData, m interface{})
if apiRegion == stateRegion {
d.SetId(apiRegion)
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 @@ -505,27 +521,42 @@ func resourceMSOSchemaSiteVrfRegionRead(d *schema.ResourceData, m interface{}) e
if apiRegion == stateRegion {
d.SetId(apiRegion)
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