Skip to content

Commit

Permalink
r/kubernetes_cluster: conditionally nil-ing the load balancer profile
Browse files Browse the repository at this point in the history
  • Loading branch information
tombuildsstuff committed Jun 9, 2020
1 parent 6cd6681 commit d4e1e0a
Showing 1 changed file with 30 additions and 24 deletions.
54 changes: 30 additions & 24 deletions azurerm/internal/services/containers/kubernetes_cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -977,29 +977,32 @@ func resourceArmKubernetesClusterUpdate(d *schema.ResourceData, meta interface{}
loadBalancerProfile.ManagedOutboundIPs = &containerservice.ManagedClusterLoadBalancerProfileManagedOutboundIPs{
Count: utils.Int32(int32(managedOutboundIPCount)),
}
} else {
// fixes: Load balancer profile must specify one of ManagedOutboundIPs, OutboundIPPrefixes and OutboundIPs.{
loadBalancerProfile.ManagedOutboundIPs = nil

// fixes: Load balancer profile must specify one of ManagedOutboundIPs, OutboundIPPrefixes and OutboundIPs.
loadBalancerProfile.OutboundIPs = nil
loadBalancerProfile.OutboundIPPrefixes = nil
}

if key := "network_profile.0.load_balancer_profile.0.outbound_ip_address_ids"; d.HasChange(key) {
publicIPAddressIDs := idsToResourceReferences(d.Get(key))
loadBalancerProfile.OutboundIPs = &containerservice.ManagedClusterLoadBalancerProfileOutboundIPs{
PublicIPs: publicIPAddressIDs,
}
} else {
// fixes: Load balancer profile must specify one of ManagedOutboundIPs, OutboundIPPrefixes and OutboundIPs.{
loadBalancerProfile.OutboundIPs = nil

// fixes: Load balancer profile must specify one of ManagedOutboundIPs, OutboundIPPrefixes and OutboundIPs.
loadBalancerProfile.ManagedOutboundIPs = nil
loadBalancerProfile.OutboundIPPrefixes = nil
}

if key := "network_profile.0.load_balancer_profile.0.outbound_ip_prefix_ids"; d.HasChange(key) {
outboundIPPrefixIDs := idsToResourceReferences(d.Get(key))
loadBalancerProfile.OutboundIPPrefixes = &containerservice.ManagedClusterLoadBalancerProfileOutboundIPPrefixes{
PublicIPPrefixes: outboundIPPrefixIDs,
}
} else {
// fixes: Load balancer profile must specify one of ManagedOutboundIPs, OutboundIPPrefixes and OutboundIPs.{
loadBalancerProfile.OutboundIPPrefixes = nil

// fixes: Load balancer profile must specify one of ManagedOutboundIPs, OutboundIPPrefixes and OutboundIPs.
loadBalancerProfile.ManagedOutboundIPs = nil
loadBalancerProfile.OutboundIPs = nil
}

if key := "network_profile.0.load_balancer_profile.0.outbound_ports_allocated"; d.HasChange(key) {
Expand Down Expand Up @@ -1437,17 +1440,24 @@ func expandKubernetesClusterNetworkProfile(input []interface{}) (*containerservi
loadBalancerSku := config["load_balancer_sku"].(string)
outboundType := config["outbound_type"].(string)

loadBalancerProfile, err := expandLoadBalancerProfile(loadBalancerProfileRaw, loadBalancerSku)
if err != nil {
return nil, err
networkProfile := containerservice.NetworkProfileType{
NetworkPlugin: containerservice.NetworkPlugin(networkPlugin),
NetworkPolicy: containerservice.NetworkPolicy(networkPolicy),
LoadBalancerSku: containerservice.LoadBalancerSku(loadBalancerSku),
OutboundType: containerservice.OutboundType(outboundType),
}

networkProfile := containerservice.NetworkProfileType{
NetworkPlugin: containerservice.NetworkPlugin(networkPlugin),
NetworkPolicy: containerservice.NetworkPolicy(networkPolicy),
LoadBalancerSku: containerservice.LoadBalancerSku(loadBalancerSku),
LoadBalancerProfile: loadBalancerProfile,
OutboundType: containerservice.OutboundType(outboundType),
if len(loadBalancerProfileRaw) > 0 {
if !strings.EqualFold(loadBalancerSku, "standard") {
return nil, fmt.Errorf("only load balancer SKU 'Standard' supports load balancer profiles. Provided load balancer type: %s", loadBalancerSku)
}

loadBalancerProfile, err := expandLoadBalancerProfile(loadBalancerProfileRaw)
if err != nil {
return nil, err
}

networkProfile.LoadBalancerProfile = loadBalancerProfile
}

if v, ok := config["dns_service_ip"]; ok && v.(string) != "" {
Expand All @@ -1473,15 +1483,11 @@ func expandKubernetesClusterNetworkProfile(input []interface{}) (*containerservi
return &networkProfile, nil
}

func expandLoadBalancerProfile(d []interface{}, loadBalancerType string) (*containerservice.ManagedClusterLoadBalancerProfile, error) {
if len(d) == 0 || d[0] != nil {
func expandLoadBalancerProfile(d []interface{}) (*containerservice.ManagedClusterLoadBalancerProfile, error) {
if d[0] == nil {
return nil, nil
}

if strings.ToLower(loadBalancerType) != "standard" {
return nil, fmt.Errorf("only load balancer SKU 'Standard' supports load balancer profiles. Provided load balancer type: %s", loadBalancerType)
}

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

profile := &containerservice.ManagedClusterLoadBalancerProfile{}
Expand Down

0 comments on commit d4e1e0a

Please sign in to comment.