From a81a846c11821dce063aac980bb9d6352447edfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Thu, 6 Jun 2024 18:12:45 +0200 Subject: [PATCH] `azurerm_kubernetes_cluster`: Support for upgrade path from Azure CNI to Azure CNI Overlay --- .../containers/kubernetes_cluster_resource.go | 23 +++++++++++++++++-- .../docs/r/kubernetes_cluster.html.markdown | 4 ++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/internal/services/containers/kubernetes_cluster_resource.go b/internal/services/containers/kubernetes_cluster_resource.go index 847d6c2ab4e0..6ba9e2c5ac9a 100644 --- a/internal/services/containers/kubernetes_cluster_resource.go +++ b/internal/services/containers/kubernetes_cluster_resource.go @@ -114,6 +114,12 @@ func resourceKubernetesCluster() *pluginsdk.Resource { pluginsdk.ForceNewIfChange("network_profile.0.network_policy", func(ctx context.Context, old, new, meta interface{}) bool { return old.(string) != "" || new.(string) != string(managedclusters.NetworkPolicyCilium) }), + pluginsdk.ForceNewIfChange("network_profile.0.pod_cidr", func(ctx context.Context, old, new, meta interface{}) bool { + return old.(string) != "" + }), + pluginsdk.ForceNewIfChange("network_profile.0.pod_cidrs", func(ctx context.Context, old, new, meta interface{}) bool { + return len(old.([]interface{})) > 0 + }), pluginsdk.ForceNewIfChange("custom_ca_trust_certificates_base64", func(ctx context.Context, old, new, meta interface{}) bool { return len(old.([]interface{})) > 0 && len(new.([]interface{})) == 0 }), @@ -1031,7 +1037,6 @@ func resourceKubernetesCluster() *pluginsdk.Resource { Type: pluginsdk.TypeString, Optional: true, Computed: true, - ForceNew: true, ValidateFunc: validate.CIDR, }, @@ -1039,7 +1044,6 @@ func resourceKubernetesCluster() *pluginsdk.Resource { Type: pluginsdk.TypeList, Optional: true, Computed: true, - ForceNew: true, Elem: &pluginsdk.Schema{ Type: pluginsdk.TypeString, ValidateFunc: validation.StringIsNotEmpty, @@ -2340,6 +2344,21 @@ func resourceKubernetesClusterUpdate(d *pluginsdk.ResourceData, meta interface{} existing.Model.Properties.NetworkProfile.NetworkDataplane = pointer.To(managedclusters.NetworkDataplane(ebpfDataPlane)) } + if key := "network_profile.0.network_plugin_mode"; d.HasChange(key) { + networkPluginMode := d.Get(key).(string) + existing.Model.Properties.NetworkProfile.NetworkPluginMode = pointer.To(managedclusters.NetworkPluginMode(networkPluginMode)) + } + + if key := "network_profile.0.pod_cidr"; d.HasChange(key) { + podCidr := d.Get(key).(string) + existing.Model.Properties.NetworkProfile.PodCidr = pointer.To(podCidr) + } + + if key := "network_profile.0.pod_cidrs"; d.HasChange(key) { + podCidrs := d.Get(key).([]interface{}) + existing.Model.Properties.NetworkProfile.PodCidrs = utils.ExpandStringSlice(podCidrs) + } + if key := "network_profile.0.outbound_type"; d.HasChange(key) { outboundType := managedclusters.OutboundType(d.Get(key).(string)) existing.Model.Properties.NetworkProfile.OutboundType = pointer.To(outboundType) diff --git a/website/docs/r/kubernetes_cluster.html.markdown b/website/docs/r/kubernetes_cluster.html.markdown index d61a413f6234..70916e38934d 100644 --- a/website/docs/r/kubernetes_cluster.html.markdown +++ b/website/docs/r/kubernetes_cluster.html.markdown @@ -699,9 +699,9 @@ A `network_profile` block supports the following: * `outbound_type` - (Optional) The outbound (egress) routing method which should be used for this Kubernetes Cluster. Possible values are `loadBalancer`, `userDefinedRouting`, `managedNATGateway` and `userAssignedNATGateway`. Defaults to `loadBalancer`. More information on supported migration paths for `outbound_type` can be found in [this documentation](https://learn.microsoft.com/azure/aks/egress-outboundtype#updating-outboundtype-after-cluster-creation). -* `pod_cidr` - (Optional) The CIDR to use for pod IP addresses. This field can only be set when `network_plugin` is set to `kubenet` or `network_plugin_mode` is set to `overlay`. Changing this forces a new resource to be created. +* `pod_cidr` - (Optional) The CIDR to use for pod IP addresses. This field can only be set when `network_plugin` is set to `kubenet` or `network_plugin_mode` is set to `overlay`. Changing an non-empty value forces a new resource to be created. -* `pod_cidrs` - (Optional) A list of CIDRs to use for pod IP addresses. For single-stack networking a single IPv4 CIDR is expected. For dual-stack networking an IPv4 and IPv6 CIDR are expected. Changing this forces a new resource to be created. +* `pod_cidrs` - (Optional) A list of CIDRs to use for pod IP addresses. For single-stack networking a single IPv4 CIDR is expected. For dual-stack networking an IPv4 and IPv6 CIDR are expected. Changing an non-empty value forces a new resource to be created. * `service_cidr` - (Optional) The Network Range used by the Kubernetes service. Changing this forces a new resource to be created.