Skip to content

Commit

Permalink
r/kubernetes_cluster: support for load balancer settings
Browse files Browse the repository at this point in the history
Porting over the changes from #5824

X-Committed-With: neil-yechenwei
  • Loading branch information
tombuildsstuff committed Jun 8, 2020
1 parent 9a3374e commit f25d744
Show file tree
Hide file tree
Showing 5 changed files with 813 additions and 22 deletions.
44 changes: 33 additions & 11 deletions azurerm/internal/services/containers/kubernetes_cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,18 @@ func resourceArmKubernetesCluster() *schema.Resource {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"outbound_ports_allocated": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
ValidateFunc: validation.IntBetween(0, 64000),
},
"idle_timeout_in_minutes": {
Type: schema.TypeInt,
Optional: true,
Default: 30,
ValidateFunc: validation.IntBetween(4, 120),
},
"managed_outbound_ip_count": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -1277,9 +1289,15 @@ func expandLoadBalancerProfile(d []interface{}, loadBalancerType string, ipCount

config := d[0].(map[string]interface{})

var managedOutboundIps *containerservice.ManagedClusterLoadBalancerProfileManagedOutboundIPs
var outboundIpPrefixes *containerservice.ManagedClusterLoadBalancerProfileOutboundIPPrefixes
var outboundIps *containerservice.ManagedClusterLoadBalancerProfileOutboundIPs
profile := &containerservice.ManagedClusterLoadBalancerProfile{}

if port, ok := config["outbound_ports_allocated"].(int); ok {
profile.AllocatedOutboundPorts = utils.Int32(int32(port))
}

if idleTimeout, ok := config["idle_timeout_in_minutes"].(int); ok {
profile.IdleTimeoutInMinutes = utils.Int32(int32(idleTimeout))
}

noChangesForLoadBalancerIps := !ipCountChanges && !ipPrefixesChanges && !outboundIpChanges
allowToSetIpCount := ipCountChanges || noChangesForLoadBalancerIps
Expand All @@ -1288,23 +1306,19 @@ func expandLoadBalancerProfile(d []interface{}, loadBalancerType string, ipCount

if ipCount := config["managed_outbound_ip_count"]; ipCount != nil && allowToSetIpCount {
if c := int32(ipCount.(int)); c > 0 {
managedOutboundIps = &containerservice.ManagedClusterLoadBalancerProfileManagedOutboundIPs{Count: &c}
profile.ManagedOutboundIPs = &containerservice.ManagedClusterLoadBalancerProfileManagedOutboundIPs{Count: &c}
}
}

if ipPrefixes := idsToResourceReferences(config["outbound_ip_prefix_ids"]); ipPrefixes != nil && allowToSetIpPrefixes {
outboundIpPrefixes = &containerservice.ManagedClusterLoadBalancerProfileOutboundIPPrefixes{PublicIPPrefixes: ipPrefixes}
profile.OutboundIPPrefixes = &containerservice.ManagedClusterLoadBalancerProfileOutboundIPPrefixes{PublicIPPrefixes: ipPrefixes}
}

if outIps := idsToResourceReferences(config["outbound_ip_address_ids"]); outIps != nil && allowToSetOutboundIp {
outboundIps = &containerservice.ManagedClusterLoadBalancerProfileOutboundIPs{PublicIPs: outIps}
profile.OutboundIPs = &containerservice.ManagedClusterLoadBalancerProfileOutboundIPs{PublicIPs: outIps}
}

return &containerservice.ManagedClusterLoadBalancerProfile{
ManagedOutboundIPs: managedOutboundIps,
OutboundIPPrefixes: outboundIpPrefixes,
OutboundIPs: outboundIps,
}, nil
return profile, nil
}

func idsToResourceReferences(set interface{}) *[]containerservice.ResourceReference {
Expand Down Expand Up @@ -1376,6 +1390,14 @@ func flattenKubernetesClusterNetworkProfile(profile *containerservice.NetworkPro
if lbp := profile.LoadBalancerProfile; lbp != nil {
lb := make(map[string]interface{})

if v := lbp.AllocatedOutboundPorts; v != nil {
lb["outbound_ports_allocated"] = v
}

if v := lbp.IdleTimeoutInMinutes; v != nil {
lb["idle_timeout_in_minutes"] = v
}

if ips := lbp.ManagedOutboundIPs; ips != nil {
if count := ips.Count; count != nil {
lb["managed_outbound_ip_count"] = count
Expand Down
Loading

0 comments on commit f25d744

Please sign in to comment.