Skip to content

Commit

Permalink
Merge pull request #201 from cisco-en-programmability/develop
Browse files Browse the repository at this point in the history
Develop v1.1.13-beta
  • Loading branch information
fmunozmiranda authored Sep 5, 2023
2 parents 80cac2c + d1a0967 commit 02b53fb
Show file tree
Hide file tree
Showing 196 changed files with 412 additions and 219 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 1.1.13-beta (September 05, 2023)
BUGFIXES:
* Fix in resource building, inconsistency with parent_name modification, updated Terraform output. #197

* dnacenter provider is not able to detect changes on infrastructure after modifications are done using DNAC GUI on the resource floor.
#188, Upgrade of resource floor to detect changes on infrastructure.

* Upgrade of resource_area about inconsistency with parent_name`
* Modified resource_sd_virtual_network_ip_pool.go to fix issue #198

## 1.1.12-beta (August 23, 2023)
BUGFIXES:
* dnacenter provider is not able to detect changes on infrastructure after modifications are done using DNAC GUI
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ HOSTNAME=hashicorp.com
NAMESPACE=edu
NAME=dnacenter
BINARY=terraform-provider-${NAME}
VERSION=1.1.12-beta
VERSION=1.1.13-beta
OS_ARCH=darwin_amd64
# Change to OS_ARCH=darwin_arm64 or your current architecture
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The following table shows the supported versions.
| 2.2.3.3 | 0.3.0-beta |
| 2.2.3.3 | 0.3.0 |
| 2.3.3.0 | 1.0.19-beta |
| 2.3.5.3 | 1.1.12-beta |
| 2.3.5.3 | 1.1.13-beta |

If your SDK, Terraform provider is older please consider updating it first.

Expand Down Expand Up @@ -66,7 +66,7 @@ terraform {
required_providers {
dnacenter = {
source = "cisco-en-programmability/dnacenter"
version = "1.1.12-beta"
version = "1.1.13-beta"
}
}
}
Expand Down
1 change: 1 addition & 0 deletions dnacenter/data_source_sda_virtual_network_ip_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func flattenSdaGetIPPoolFromSdaVirtualNetworkItem(item *dnacentersdkgo.ResponseS
respItem["scalable_group_name"] = item.ScalableGroupName
respItem["is_l2_flooding_enabled"] = boolPtrToString(item.IsL2FloodingEnabled)
respItem["is_this_critical_pool"] = boolPtrToString(item.IsThisCriticalPool)
respItem["vlan_name"] = item.VLANName
return []map[string]interface{}{
respItem,
}
Expand Down
143 changes: 129 additions & 14 deletions dnacenter/data_source_site.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ func dataSourceSiteRead(ctx context.Context, d *schema.ResourceData, m interface

log.Printf("[DEBUG] Retrieved response %+v", responseInterfaceToString(*response1))

vItems1 := flattenSitesGetSiteItems(response1.Response)
parameters := d.Get("parameters").([]interface{})
vItems1 := flattenSitesGetSiteItems(response1.Response, parameters)
if err := d.Set("items", vItems1); err != nil {
diags = append(diags, diagError(
"Failure when setting GetSite response",
Expand All @@ -179,7 +180,7 @@ func dataSourceSiteRead(ctx context.Context, d *schema.ResourceData, m interface
return diags
}

func flattenSitesGetSiteItems(items *[]dnacentersdkgo.ResponseSitesGetSiteResponse) []map[string]interface{} {
func flattenSitesGetSiteItems(items *[]dnacentersdkgo.ResponseSitesGetSiteResponse, parameters []interface{}) []map[string]interface{} {
if items == nil {
return nil
}
Expand All @@ -188,7 +189,7 @@ func flattenSitesGetSiteItems(items *[]dnacentersdkgo.ResponseSitesGetSiteRespon
respItem := make(map[string]interface{})
respItem["parent_id"] = item.ParentID
respItem["name"] = item.Name
respItem["additional_info"] = flattenSitesGetSiteItemsAdditionalInfo(item.AdditionalInfo)
respItem["additional_info"] = flattenSitesGetSiteItemsAdditionalInfo(item.AdditionalInfo, parameters)
respItem["site_hierarchy"] = item.SiteHierarchy
respItem["site_name_hierarchy"] = item.SiteNameHierarchy
respItem["instance_tenant_id"] = item.InstanceTenantID
Expand Down Expand Up @@ -219,7 +220,7 @@ func flattenSitesGetFloorItems(items *[]dnacentersdkgo.ResponseSitesGetFloorResp
return respItems
}

func flattenSitesGetAreaItems(items *[]dnacentersdkgo.ResponseSitesGetAreaResponse) []map[string]interface{} {
func flattenSitesGetAreaItems(items *[]dnacentersdkgo.ResponseSitesGetAreaResponse, parameters []interface{}) []map[string]interface{} {
if items == nil {
return nil
}
Expand All @@ -228,7 +229,7 @@ func flattenSitesGetAreaItems(items *[]dnacentersdkgo.ResponseSitesGetAreaRespon
respItem := make(map[string]interface{})
respItem["parent_id"] = item.ParentID
respItem["name"] = item.Name
respItem["additional_info"] = flattenSitesGetAreaItemsAdditionalInfo(item.AdditionalInfo)
respItem["additional_info"] = flattenSitesGetAreaItemsAdditionalInfo(item.AdditionalInfo, parameters)
respItem["site_hierarchy"] = item.SiteHierarchy
respItem["site_name_hierarchy"] = item.SiteNameHierarchy
respItem["instance_tenant_id"] = item.InstanceTenantID
Expand All @@ -239,9 +240,10 @@ func flattenSitesGetAreaItems(items *[]dnacentersdkgo.ResponseSitesGetAreaRespon
return respItems
}

func flattenSitesGetSiteParams(items *[]dnacentersdkgo.ResponseSitesGetSiteResponse) map[string]interface{} {
func flattenSitesGetSiteParams(items *[]dnacentersdkgo.ResponseSitesGetSiteResponse, parameters []interface{}) map[string]interface{} {
respParams := make(map[string]interface{})
buildings := make([]map[string]interface{}, 0)
parentName := getParametersOfLastUpdatedBuilding(parameters, "parent_name", "building")

for _, item := range *items {
for _, additionalInfo := range item.AdditionalInfo {
Expand All @@ -262,7 +264,7 @@ func flattenSitesGetSiteParams(items *[]dnacentersdkgo.ResponseSitesGetSiteRespo
"latitude": latitude,
"longitude": longitude,
"name": item.Name,
"parent_name": "Global",
"parent_name": parentName,
//"type": attributes["type"],
}
buildings = append(buildings, building)
Expand All @@ -275,19 +277,78 @@ func flattenSitesGetSiteParams(items *[]dnacentersdkgo.ResponseSitesGetSiteRespo
},
}
respParams["type"] = "building"
if len(parameters) > 0 {
respParams["site_id"] = parameters[0].(map[string]interface{})["site_id"].(string)
}

return respParams

}

func flattenSitesGetAreaParams(items *[]dnacentersdkgo.ResponseSitesGetAreaResponse) map[string]interface{} {
func flattenSitesGetFloorParams(items *[]dnacentersdkgo.ResponseSitesGetFloorResponse, parameters []interface{}) map[string]interface{} {
respParams := make(map[string]interface{})
areas := make([]map[string]interface{}, 0)
floors := make([]map[string]interface{}, 0)
parentName := getParametersOfLastUpdatedBuilding(parameters, "parent_name", "floor")

for _, item := range *items {
for _, additionalInfo := range item.AdditionalInfo {
attributes := additionalInfo.Attributes
floorNumber, err := strconv.ParseFloat(attributes.FloorNumber, 64)
if err != nil {
log.Printf("Error in parse float floorNumber")
}

height, err := strconv.ParseFloat(attributes.Height, 64)
if err != nil {
log.Printf("Error in parse float height")
}

length, err := strconv.ParseFloat(attributes.Length, 64)
if err != nil {
log.Printf("Error in parse float length")
}

width, err := strconv.ParseFloat(attributes.Width, 64)
if err != nil {
log.Printf("Error in parse float width")
}

floor := map[string]interface{}{
"floor_number": floorNumber,
"height": height,
"length": length,
"name": attributes.Name,
"parent_name": parentName,
"rf_model": attributes.RfModel,
"width": width,
}
floors = append(floors, floor)
}
}

respParams["site"] = []map[string]interface{}{
{
"floor": floors,
},
}
respParams["type"] = "floor"
if len(parameters) > 0 {
respParams["site_id"] = parameters[0].(map[string]interface{})["site_id"].(string)
}

return respParams

}

func flattenSitesGetAreaParams(items *[]dnacentersdkgo.ResponseSitesGetAreaResponse, parameters []interface{}) map[string]interface{} {
respParams := make(map[string]interface{})
areas := make([]map[string]interface{}, 0)
parentName := getParametersOfLastUpdatedBuilding(parameters, "parent_name", "area")
for _, item := range *items {

area := map[string]interface{}{
"name": item.Name,
"name": item.Name,
"parent_name": parentName,
//"type": attributes["type"],
}
areas = append(areas, area)
Expand All @@ -299,12 +360,16 @@ func flattenSitesGetAreaParams(items *[]dnacentersdkgo.ResponseSitesGetAreaRespo
"area": areas,
},
}
respParams["type"] = "area"

respParams["type"] = "area"
if len(parameters) > 0 {
respParams["site_id"] = parameters[0].(map[string]interface{})["site_id"].(string)
}
return respParams

}

/*
func flattenSitesGetSiteItem(item *dnacentersdkgo.ResponseSitesGetSiteResponse) []map[string]interface{} {
if item == nil {
return nil
Expand All @@ -319,10 +384,11 @@ func flattenSitesGetSiteItem(item *dnacentersdkgo.ResponseSitesGetSiteResponse)
respItems = append(respItems, respItem)
return respItems
}
}*/

func flattenSitesGetSiteItemsAdditionalInfo(items []dnacentersdkgo.ResponseSitesGetSiteResponseAdditionalInfo) []map[string]interface{} {
func flattenSitesGetSiteItemsAdditionalInfo(items []dnacentersdkgo.ResponseSitesGetSiteResponseAdditionalInfo, parameters []interface{}) []map[string]interface{} {
var respItems []map[string]interface{}
parentName := getParametersOfLastUpdatedBuilding(parameters, "parent_name", "building")
for _, item := range items {
respItem := make(map[string]interface{})
respItem["name_space"] = item.Namespace
Expand All @@ -341,6 +407,7 @@ func flattenSitesGetSiteItemsAdditionalInfo(items []dnacentersdkgo.ResponseSites
"height": item.Attributes.Height,
"rfmodel": item.Attributes.RfModel,
"floorindex": item.Attributes.FloorIndex,
"parent_name": parentName,
},
}
respItems = append(respItems, respItem)
Expand Down Expand Up @@ -369,15 +436,18 @@ func flattenSitesGetFloorItemsAdditionalInfo(items []dnacentersdkgo.ResponseSite
return respItems
}

func flattenSitesGetAreaItemsAdditionalInfo(items []dnacentersdkgo.ResponseSitesGetAreaResponseAdditionalInfo) []map[string]interface{} {
func flattenSitesGetAreaItemsAdditionalInfo(items []dnacentersdkgo.ResponseSitesGetAreaResponseAdditionalInfo, parameters []interface{}) []map[string]interface{} {
var respItems []map[string]interface{}
parentName := getParametersOfLastUpdatedBuilding(parameters, "parent_name", "area")
for _, item := range items {
respItem := make(map[string]interface{})
respItem["name_space"] = item.Namespace
respItem["attributes"] = []map[string]interface{}{
{
"addressinheritedfrom": item.Attributes.AddressInheritedFrom,
"parent_name": parentName,
"type": item.Attributes.Type,
"name": item.Attributes.Name,
},
}
respItems = append(respItems, respItem)
Expand Down Expand Up @@ -406,3 +476,48 @@ func flattenSitesGetSiteItemsAdditionalInfoAtributes(item *dnacentersdkgo.Respon

return respItem
}

func getParametersOfLastUpdatedBuilding(parameters []interface{}, searchValue string, typeSite string) string {
for _, param := range parameters {
paramData, ok := param.(map[string]interface{})
if !ok {
log.Printf("Error in paramData")
continue
}

siteDataArray, ok := paramData["site"].([]interface{})
if !ok || len(siteDataArray) == 0 {
log.Printf("Error in enter site")
continue
}

siteData, ok := siteDataArray[0].(map[string]interface{})
if !ok {
log.Printf("Error in enter data site ")
continue
}

resourceDataArray, ok := siteData[typeSite].([]interface{})
if !ok || len(resourceDataArray) == 0 {
log.Printf("Error in enter resource ")
continue
}

resourceData, ok := resourceDataArray[0].(map[string]interface{})
if !ok {
log.Printf("Error in enter data resource ")
continue
}

value, ok := resourceData[searchValue].(string)
if !ok {
log.Printf("Error in get value ")
continue
}

return value
}

return ""

}
20 changes: 10 additions & 10 deletions dnacenter/resource_area.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,23 +322,23 @@ func resourceAreaRead(ctx context.Context, d *schema.ResourceData, m interface{}
d.SetId("")
return diags
}
vItem1 := flattenSitesGetAreaItems(response1.Response)
parameters := d.Get("parameters").([]interface{})
vItem1 := flattenSitesGetAreaItems(response1.Response, parameters)
log.Printf("[DEBUG] response flatten sent => %v", responseInterfaceToString(vItem1))
if err := d.Set("item", vItem1); err != nil {
diags = append(diags, diagError(
"Failure when setting GetSite search response",
err))
return diags
}
/*
vItem2 := flattenSitesGetAreaParams(response1.Response)
if err := d.Set("parameters", []map[string]interface{}{vItem2}); err != nil {
diags = append(diags, diagError(
"Failure when setting GetSite search response",
err))
log.Printf("Dentro")
return diags
}*/

vItem2 := flattenSitesGetAreaParams(response1.Response, parameters)
if err := d.Set("parameters", []map[string]interface{}{vItem2}); err != nil {
diags = append(diags, diagError(
"Failure when setting GetSite search response",
err))
return diags
}

}
return diags
Expand Down
10 changes: 7 additions & 3 deletions dnacenter/resource_building.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ func resourceBuilding() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"parent_name": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
},
},
},
Expand Down Expand Up @@ -385,8 +389,8 @@ func resourceBuildingRead(ctx context.Context, d *schema.ResourceData, m interfa
d.SetId("")
return diags
}

vItem1 := flattenSitesGetSiteItems(response1.Response)
parameters := d.Get("parameters").([]interface{})
vItem1 := flattenSitesGetSiteItems(response1.Response, parameters)
log.Printf("[DEBUG] response flatten sent => %v", responseInterfaceToString(vItem1))
if err := d.Set("item", vItem1); err != nil {
diags = append(diags, diagError(
Expand All @@ -395,7 +399,7 @@ func resourceBuildingRead(ctx context.Context, d *schema.ResourceData, m interfa
return diags
}

vItem2 := flattenSitesGetSiteParams(response1.Response)
vItem2 := flattenSitesGetSiteParams(response1.Response, parameters)
if err := d.Set("parameters", []map[string]interface{}{vItem2}); err != nil {
diags = append(diags, diagError(
"Failure when setting GetSite search response",
Expand Down
Loading

0 comments on commit 02b53fb

Please sign in to comment.