diff --git a/internal/services/containers/kubernetes_cluster_network_resource_test.go b/internal/services/containers/kubernetes_cluster_network_resource_test.go index a203fb510a43..fa322b52e7d1 100644 --- a/internal/services/containers/kubernetes_cluster_network_resource_test.go +++ b/internal/services/containers/kubernetes_cluster_network_resource_test.go @@ -832,7 +832,14 @@ func TestAccKubernetesCluster_ebpfDataPlane(t *testing.T) { data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.ebpfDataPlane(data), + Config: r.ebpfDataPlane(data, ""), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.ebpfDataPlane(data, "cilium"), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), @@ -3460,7 +3467,12 @@ resource "azurerm_kubernetes_cluster" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, currentKubernetesVersion, data.RandomInteger) } -func (KubernetesClusterResource) ebpfDataPlane(data acceptance.TestData) string { +func (KubernetesClusterResource) ebpfDataPlane(data acceptance.TestData, ebpfDataPlane string) string { + ebpfDataPlaneValue := "null" + if ebpfDataPlane != "" { + ebpfDataPlaneValue = fmt.Sprintf(`"%s"`, ebpfDataPlane) + } + return fmt.Sprintf(` provider "azurerm" { features {} @@ -3502,11 +3514,11 @@ resource "azurerm_kubernetes_cluster" "test" { network_profile { pod_cidr = "192.168.0.0/16" network_plugin = "azure" - ebpf_data_plane = "cilium" + ebpf_data_plane = %[3]s network_plugin_mode = "overlay" } } -`, "westcentralus", data.RandomInteger) +`, data.Locations.Primary, data.RandomInteger, ebpfDataPlaneValue) } func (KubernetesClusterResource) networkPluginMode(data acceptance.TestData) string { diff --git a/internal/services/containers/kubernetes_cluster_resource.go b/internal/services/containers/kubernetes_cluster_resource.go index 3caa9f1c3eec..7e904aea5048 100644 --- a/internal/services/containers/kubernetes_cluster_resource.go +++ b/internal/services/containers/kubernetes_cluster_resource.go @@ -87,6 +87,9 @@ func resourceKubernetesCluster() *pluginsdk.Resource { } return true }), + pluginsdk.ForceNewIfChange("network_profile.0.ebpf_data_plane", func(ctx context.Context, old, new, meta interface{}) bool { + return old != "" + }), func(ctx context.Context, d *schema.ResourceDiff, meta interface{}) error { if d.HasChange("oidc_issuer_enabled") { d.SetNewComputed("oidc_issuer_url") @@ -1052,7 +1055,6 @@ func resourceKubernetesCluster() *pluginsdk.Resource { "ebpf_data_plane": { Type: pluginsdk.TypeString, Optional: true, - ForceNew: true, ValidateFunc: validation.StringInSlice([]string{ string(managedclusters.NetworkDataplaneCilium), }, false), @@ -2030,11 +2032,6 @@ func resourceKubernetesClusterUpdate(d *pluginsdk.ResourceData, meta interface{} networkProfile := *existing.Model.Properties.NetworkProfile - if networkProfile.LoadBalancerProfile == nil && networkProfile.NatGatewayProfile == nil { - // on of the profiles should be present - return fmt.Errorf("both `loadBalancerProfile` and `natGatewayProfile` are nil in Azure") - } - if networkProfile.LoadBalancerProfile != nil { loadBalancerProfile := *networkProfile.LoadBalancerProfile @@ -2141,6 +2138,11 @@ func resourceKubernetesClusterUpdate(d *pluginsdk.ResourceData, meta interface{} existing.Model.Properties.NetworkProfile.NatGatewayProfile = &natGatewayProfile } + + if key := "network_profile.0.ebpf_data_plane"; d.HasChange(key) { + ebpfDataPlane := d.Get(key).(string) + existing.Model.Properties.NetworkProfile.NetworkDataplane = pointer.To(managedclusters.NetworkDataplane(ebpfDataPlane)) + } } 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 1e28ae703065..e82cf0ace854 100644 --- a/website/docs/r/kubernetes_cluster.html.markdown +++ b/website/docs/r/kubernetes_cluster.html.markdown @@ -673,7 +673,7 @@ A `network_profile` block supports the following: -> **Note:** `docker_bridge_cidr` has been deprecated as the API no longer supports it and will be removed in version 4.0 of the provider. -* `ebpf_data_plane` - (Optional) Specifies the eBPF data plane used for building the Kubernetes network. Possible value is `cilium`. Changing this forces a new resource to be created. +* `ebpf_data_plane` - (Optional) Specifies the eBPF data plane used for building the Kubernetes network. Possible value is `cilium`. Disabling this forces a new resource to be created. ~> **Note:** When `ebpf_data_plane` is set to `cilium`, the `network_plugin` field can only be set to `azure`.