From 3f85dee3701d25a7c8791e39b9d39534a2e1d063 Mon Sep 17 00:00:00 2001 From: stephybun Date: Tue, 27 Feb 2024 07:20:46 +0100 Subject: [PATCH] support migration of outbound types (#25021) --- ...ubernetes_cluster_network_resource_test.go | 24 ++++++++++++++++++- .../containers/kubernetes_cluster_resource.go | 5 +++- .../docs/r/kubernetes_cluster.html.markdown | 2 +- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/internal/services/containers/kubernetes_cluster_network_resource_test.go b/internal/services/containers/kubernetes_cluster_network_resource_test.go index bcbe4fb39b89..b55c0c6aa917 100644 --- a/internal/services/containers/kubernetes_cluster_network_resource_test.go +++ b/internal/services/containers/kubernetes_cluster_network_resource_test.go @@ -392,6 +392,28 @@ func TestAccKubernetesCluster_outboundTypeLoadBalancer(t *testing.T) { }) } +func TestAccKubernetesCluster_outboundTypeUpdate(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") + r := KubernetesClusterResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.managedNatGatewayConfig(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.outboundTypeLoadBalancerConfig(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + func TestAccKubernetesCluster_natGatewayProfile(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") r := KubernetesClusterResource{} @@ -2121,7 +2143,7 @@ resource "azurerm_kubernetes_cluster" "test" { network_profile { network_plugin = "kubenet" - load_balancer_sku = "basic" + load_balancer_sku = "standard" pod_cidr = "10.244.0.0/16" service_cidr = "10.0.0.0/16" dns_service_ip = "10.0.0.10" diff --git a/internal/services/containers/kubernetes_cluster_resource.go b/internal/services/containers/kubernetes_cluster_resource.go index 92cc12172a57..a914042cd1e8 100644 --- a/internal/services/containers/kubernetes_cluster_resource.go +++ b/internal/services/containers/kubernetes_cluster_resource.go @@ -1135,7 +1135,6 @@ func resourceKubernetesCluster() *pluginsdk.Resource { "outbound_type": { Type: pluginsdk.TypeString, Optional: true, - ForceNew: true, Default: string(managedclusters.OutboundTypeLoadBalancer), ValidateFunc: validation.StringInSlice([]string{ string(managedclusters.OutboundTypeLoadBalancer), @@ -2158,6 +2157,10 @@ func resourceKubernetesClusterUpdate(d *pluginsdk.ResourceData, meta interface{} ebpfDataPlane := d.Get(key).(string) existing.Model.Properties.NetworkProfile.NetworkDataplane = pointer.To(managedclusters.NetworkDataplane(ebpfDataPlane)) } + + if key := "network_profile.0.outbound_type"; d.HasChange(key) { + existing.Model.Properties.NetworkProfile.OutboundType = pointer.To(managedclusters.OutboundType(d.Get(key).(string))) + } } if d.HasChange("service_mesh_profile") { updateCluster = true diff --git a/website/docs/r/kubernetes_cluster.html.markdown b/website/docs/r/kubernetes_cluster.html.markdown index 1bb3f649235e..391cb8e5107e 100644 --- a/website/docs/r/kubernetes_cluster.html.markdown +++ b/website/docs/r/kubernetes_cluster.html.markdown @@ -703,7 +703,7 @@ A `network_profile` block supports the following: ~> **Note:** When `network_plugin_mode` is set to `overlay`, the `network_plugin` field can only be set to `azure`. When upgrading from Azure CNI without overlay, `pod_subnet_id` must be specified. -* `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`. Changing this forces a new resource to be created. +* `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`. Changing this forces a new resource to be created.