Skip to content

Commit

Permalink
Resource dnacenter_reserve_ip_subpool does not detect changes made o…
Browse files Browse the repository at this point in the history
…utside terraform #217
  • Loading branch information
fmunoz committed Nov 20, 2023
1 parent fdaff72 commit 4341415
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 38 deletions.
19 changes: 19 additions & 0 deletions dnacenter/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dnacenter
import (
"encoding/json"
"fmt"
"log"
"strconv"
)

Expand Down Expand Up @@ -91,9 +92,27 @@ func getResourceItem(item interface{}) *map[string]interface{} {
return &vvItem
}

func sliceInterfaceToSliceString(v []interface{}) []string {
newValue := []string{}
for _, v2 := range v {
value, ok := v2.([]interface{})
if !ok {
log.Print("sliceInterfaceToSliceString: Nil")
return nil
}

for _, i := range value {
newValue = append(newValue, interfaceToString(i))
}
}
return newValue
}

func interfaceToSliceString(v interface{}) []string {
value, ok := v.([]interface{})
log.Printf("interfaceToSliceString interface: %s", responseInterfaceToSliceString(v))
if !ok {
log.Print("interfaceToSliceString: Nil")
return nil
}
newValue := []string{}
Expand Down
34 changes: 29 additions & 5 deletions dnacenter/data_source_reserve_ip_subpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func flattenNetworkSettingsGetReserveIPSubpoolParameters(items *dnacentersdkgo.R
respItem["ipv6_address_space"] = boolPtrToString(items.IPv6AddressSpace)
respItem["ipv4_global_pool"] = items.IPv4GlobalPool
respItem["ipv4_prefix"] = boolPtrToString(items.IPv4Prefix)
respItem["ipv4_prefix_length"] = interfaceToIntPtr(items.IPv4PrefixLength)
respItem["ipv4_prefix_length"] = items.IPv4PrefixLength
respItem["ipv4_subnet"] = items.IPv4Subnet
respItem["ipv4_gate_way"] = items.IPv4GateWay
respItem["ipv4_dhcp_servers"] = items.IPv4DhcpServers
Expand All @@ -352,6 +352,30 @@ func flattenNetworkSettingsGetReserveIPSubpoolParameters(items *dnacentersdkgo.R
return respItems
}

func flattenNetworkSettingsGetReserveIPSubpoolParametersDhcpServers(items []string) []interface{} {
if items == nil {
return nil
}
var respItems []interface{}
for _, item := range items {
respItem := item
respItems = append(respItems, responseInterfaceToString(respItem))
}
return respItems
}

func flattenNetworkSettingsGetReserveIPSubpoolParametersDnsServers(items []string) []interface{} {
if items == nil {
return nil
}
var respItems []interface{}
for _, item := range items {
respItem := item
respItems = append(respItems, responseInterfaceToString(respItem))
}
return respItems
}

func flattenNetworkSettingsGetReserveIPSubpoolItemsIPPools(items *[]dnacentersdkgo.ResponseNetworkSettingsGetReserveIPSubpoolResponseIPPools) []map[string]interface{} {
if items == nil {
return nil
Expand Down Expand Up @@ -384,12 +408,12 @@ func flattenNetworkSettingsGetReserveIPSubpoolItemsIPPools(items *[]dnacentersdk
return respItems
}

func flattenNetworkSettingsGetReserveIPSubpoolItemsIPPoolsDhcpServerIPs(items *[]dnacentersdkgo.ResponseNetworkSettingsGetReserveIPSubpoolResponseIPPoolsDhcpServerIPs) []interface{} {
func flattenNetworkSettingsGetReserveIPSubpoolItemsIPPoolsDhcpServerIPs(items []string) []interface{} {
if items == nil {
return nil
}
var respItems []interface{}
for _, item := range *items {
for _, item := range items {
respItem := item
respItems = append(respItems, responseInterfaceToString(respItem))
}
Expand All @@ -406,12 +430,12 @@ func flattenNetworkSettingsGetReserveIPSubpoolItemsIPPoolsClientOptions(item *dn

}

func flattenNetworkSettingsGetReserveIPSubpoolItemsIPPoolsDNSServerIPs(items *[]dnacentersdkgo.ResponseNetworkSettingsGetReserveIPSubpoolResponseIPPoolsDNSServerIPs) []interface{} {
func flattenNetworkSettingsGetReserveIPSubpoolItemsIPPoolsDNSServerIPs(items []string) []interface{} {
if items == nil {
return nil
}
var respItems []interface{}
for _, item := range *items {
for _, item := range items {
respItem := item
respItems = append(respItems, responseInterfaceToString(respItem))
}
Expand Down
15 changes: 10 additions & 5 deletions dnacenter/resource_reserve_ip_subpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ func resourceReserveIPSubpoolRead(ctx context.Context, d *schema.ResourceData, m
return diags
}
request1 := expandRequestReserveIPSubpoolReserveIPSubpool(ctx, "parameters.0", d)
log.Printf("[DEBUG] Retrieved response %+v", responseInterfaceToString(*response1))
updatedParameters := updateReserveIpPoolParameters(request1, response1)

vParameters := flattenNetworkSettingsGetReserveIPSubpoolParameters(updatedParameters)
Expand Down Expand Up @@ -869,22 +870,26 @@ func searchNetworkSettingsGetReserveIPSubpool(m interface{}, queryParams dnacent
}

func updateReserveIpPoolParameters(request *dnacentersdkgo.RequestNetworkSettingsReserveIPSubpool, response *dnacentersdkgo.ResponseNetworkSettingsGetReserveIPSubpoolResponse) *dnacentersdkgo.RequestNetworkSettingsReserveIPSubpool {
log.Printf("IPPOOLREQUEST %s", responseInterfaceToString(request))
for _, v := range *response.IPPools {
// log.Printf("IPPOOL %s", responseInterfaceToString(v))
log.Printf("IPPOOL %s", responseInterfaceToString(v))
log.Printf("IPPOOL Dhcp %s", responseInterfaceToString(v.DhcpServerIPs))
if v.IPv6 != nil && *v.IPv6 {
if v.IPPoolName == request.Name {
request.Name = v.IPPoolName
request.IPv6DhcpServers = interfaceToSliceString(v.DhcpServerIPs)
request.IPv6DNSServers = interfaceToSliceString(v.DNSServerIPs)
request.IPv6DhcpServers = v.DhcpServerIPs
request.IPv6DNSServers = v.DNSServerIPs
}
// request.SLAacSupport =
} else {
if v.IPPoolName == request.Name {
request.Name = v.IPPoolName
request.IPv4DhcpServers = interfaceToSliceString(v.DhcpServerIPs)
request.IPv4DNSServers = interfaceToSliceString(v.DNSServerIPs)
request.IPv4DhcpServers = v.DhcpServerIPs
request.IPv4DNSServers = v.DNSServerIPs
}
}
}

log.Printf("IPPOOLREQUEST %s", responseInterfaceToString(request))
return request
}
22 changes: 10 additions & 12 deletions examples/samples/resources/dnacenter_reserve_ip_subpool/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,22 @@ resource "dnacenter_reserve_ip_subpool" "example" {
ipv4_global_pool = "10.0.0.0"

//id = "string"
# ipv4_dhcp_servers = []
# ipv4_dns_servers = []
ipv4_gate_way = "10.0.0.1"
ipv4_dhcp_servers = ["abc.def.ghi.jkl"]
ipv4_dns_servers = ["abc.def.ghi.jkl"]
ipv4_gate_way = "abc.def.ghi.jkl"
ipv4_prefix_length = 27
ipv4_subnet = "17"
# ipv4_total_host = 2
# ipv6_address_space = "false"
ipv6_dhcp_servers = [
"2004:192:3::40"
]
# ipv6_dns_servers = []
# ipv6_gate_way = "string2"
# ipv6_global_pool = "string"
ipv6_dhcp_servers = ["abc.def.ghi.jkl2"]
ipv6_dns_servers = ["abc.def.ghi.jkl"]
ipv6_gate_way = "abc.def.ghi.jkl"
ipv6_global_pool = "10.0.0.1"
# ipv6_prefix = "false"
# ipv6_prefix_length = 1
# ipv6_subnet = "2"
ipv6_prefix_length = 10
ipv6_subnet = "2"
# ipv6_total_host = 2
name = "80net_nyc"
name = "devhf_SVG_medtek_vlan855"
site_id = "4e1fb72d-4896-49d7-aa98-57b64d93ce0a"
/*slaac_support = "false"
type = "string"*/
Expand Down
15 changes: 2 additions & 13 deletions examples/samples/resources/dnacenter_wireless_profile/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,6 @@ resource "dnacenter_wireless_profile" "example" {
interface_name = "management"
name = "BTest22"
type = "string"
}
ssid_details {
enable_fabric = "true"
flex_connect {
enable_flex_connect = "false"
local_to_vlan = 0
}
interface_name = "management"
name = "new2"
type = "eduroam"
}
ssid_details {
enable_fabric = "true"
Expand All @@ -54,17 +44,16 @@ resource "dnacenter_wireless_profile" "example" {
name = "ATest222"
type = "eduroam"
}
ssid_details {
ssid_details {
enable_fabric = "true"
flex_connect {
enable_flex_connect = "false"
local_to_vlan = 0
}
interface_name = "management"
name = "new"
type = "eduroam"
type = "string"
}

}
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ require (
)

require (
github.com/cisco-en-programmability/dnacenter-go-sdk/v5 v5.0.18
github.com/cisco-en-programmability/dnacenter-go-sdk/v5 v5.0.20
github.com/mattn/go-isatty v0.0.19 // indirect
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgI
github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
github.com/cisco-en-programmability/dnacenter-go-sdk/v5 v5.0.18 h1:J/6QK10VJd/T2jd44blLwu6zP/vgN+EdpQ9aZSTfiNc=
github.com/cisco-en-programmability/dnacenter-go-sdk/v5 v5.0.18/go.mod h1:4Km+JuiyL/LsNRvO4dMWUSUVbnNBRmbwzJMU1oUbn0E=
github.com/cisco-en-programmability/dnacenter-go-sdk/v5 v5.0.20 h1:6TGimRLXTSWi40QaALp0+P+CU95AKMd1REZ35bBUBaA=
github.com/cisco-en-programmability/dnacenter-go-sdk/v5 v5.0.20/go.mod h1:4Km+JuiyL/LsNRvO4dMWUSUVbnNBRmbwzJMU1oUbn0E=
github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I=
github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs=
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
Expand Down

0 comments on commit 4341415

Please sign in to comment.