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

Fix policy segment and lb pool resources #473

Merged
merged 1 commit into from
Sep 30, 2020
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
5 changes: 4 additions & 1 deletion nsxt/resource_nsxt_policy_lb_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,10 @@ func resourceNsxtPolicyLBPoolRead(d *schema.ResourceData, m interface{}) error {
d.Set("active_monitor_path", "")
}
d.Set("algorithm", obj.Algorithm)
d.Set("member_group", obj.MemberGroup)
err = setPolicyPoolMemberGroupInSchema(d, obj.MemberGroup)
if err != nil {
return err
}
err = setPolicyPoolMembersInSchema(d, obj.Members)
if err != nil {
return err
Expand Down
46 changes: 32 additions & 14 deletions nsxt/segment_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package nsxt
import (
"fmt"
"log"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
Expand Down Expand Up @@ -465,7 +466,12 @@ func getSegmentSubnetDhcpConfigFromSchema(schemaConfig map[string]interface{}) (
}

if len(excludedRanges) > 0 {
config.ExcludedRanges = interface2StringList(excludedRanges)
var rangeList []string
for _, excludedRange := range excludedRanges {
rangeMap := excludedRange.(map[string]interface{})
rangeList = append(rangeList, fmt.Sprintf("%s-%s", rangeMap["start"].(string), rangeMap["end"].(string)))
}
config.ExcludedRanges = rangeList
}

if leaseTime > 0 {
Expand All @@ -492,6 +498,7 @@ func setSegmentSubnetDhcpConfigInSchema(schemaConfig map[string]interface{}, sub
converter := bindings.NewTypeConverter()
converter.SetMode(bindings.REST)

var resultConfigs []map[string]interface{}
resultConfig := make(map[string]interface{})

if subnetConfig.DhcpConfig == nil {
Expand Down Expand Up @@ -524,7 +531,8 @@ func setSegmentSubnetDhcpConfigInSchema(schemaConfig map[string]interface{}, sub
resultConfig["dhcp_generic_option"] = opts
}
}
schemaConfig["dhcp_v4_config"] = resultConfig
resultConfigs = append(resultConfigs, resultConfig)
schemaConfig["dhcp_v4_config"] = resultConfigs
return nil
}

Expand All @@ -541,9 +549,21 @@ func setSegmentSubnetDhcpConfigInSchema(schemaConfig map[string]interface{}, sub
resultConfig["dns_servers"] = dhcpV6Config.DnsServers
resultConfig["sntp_servers"] = dhcpV6Config.SntpServers
resultConfig["domain_names"] = dhcpV6Config.DomainNames
resultConfig["excluded_range"] = dhcpV6Config.ExcludedRanges
var excludedRanges []map[string]interface{}
for _, excludedRange := range dhcpV6Config.ExcludedRanges {
addresses := strings.Split(excludedRange, "-")
if len(addresses) == 2 {
rangeMap := make(map[string]interface{})
rangeMap["start"] = addresses[0]
rangeMap["end"] = addresses[1]
excludedRanges = append(excludedRanges, rangeMap)
}
}

resultConfig["excluded_range"] = excludedRanges

schemaConfig["dhcp_v6_config"] = resultConfig
resultConfigs = append(resultConfigs, resultConfig)
schemaConfig["dhcp_v6_config"] = resultConfigs
return nil
}

Expand Down Expand Up @@ -588,13 +608,12 @@ func policySegmentResourceToInfraStruct(id string, d *schema.ResourceData, isVla
var vlanIds []string
var subnets []interface{}
var subnetStructs []model.SegmentSubnet
if isVlan {
// VLAN specific fields
for _, vlanID := range d.Get("vlan_ids").([]interface{}) {
vlanIds = append(vlanIds, vlanID.(string))
}
obj.VlanIds = vlanIds
} else {
// VLAN specific fields
for _, vlanID := range d.Get("vlan_ids").([]interface{}) {
vlanIds = append(vlanIds, vlanID.(string))
}
obj.VlanIds = vlanIds
if !isVlan {
// overlay specific fields
connectivityPath := d.Get("connectivity_path").(string)
overlayID, exists := d.GetOk("overlay_id")
Expand Down Expand Up @@ -1132,9 +1151,8 @@ func nsxtPolicySegmentRead(d *schema.ResourceData, m interface{}, isVlan bool) e
d.Set("domain_name", obj.DomainName)
d.Set("transport_zone_path", obj.TransportZonePath)

if isVlan {
d.Set("vlan_ids", obj.VlanIds)
} else {
d.Set("vlan_ids", obj.VlanIds)
if !isVlan {
if obj.OverlayId != nil {
d.Set("overlay_id", int(*obj.OverlayId))
} else {
Expand Down