Skip to content

Commit

Permalink
azurerm_kubernetes_cluster - mark ebpf_data_plane not force new (#…
Browse files Browse the repository at this point in the history
…22952)

* `azurerm_kubernetes_cluster` - mark `ebpf_data_plane` not force new

* Update internal/services/containers/kubernetes_cluster_resource.go

Co-authored-by: stephybun <[email protected]>

* make fmt

* rename unused

---------

Co-authored-by: stephybun <[email protected]>
  • Loading branch information
ms-henglu and stephybun authored Aug 21, 2023
1 parent 2f48d16 commit 8304b12
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
Expand Down Expand Up @@ -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 {}
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 8 additions & 6 deletions internal/services/containers/kubernetes_cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/kubernetes_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down

0 comments on commit 8304b12

Please sign in to comment.