Skip to content

Commit

Permalink
azurerm_kubernetes_cluster - support for the support_plan property (
Browse files Browse the repository at this point in the history
#23970)

* `azurerm_kubernetes_cluster` - support for the `support_plan` property

* update

* add default value

* add docs

* Update internal/services/containers/kubernetes_cluster_resource.go

Co-authored-by: stephybun <steph@hashicorp.com>

* minor fix

---------

Co-authored-by: stephybun <steph@hashicorp.com>
  • Loading branch information
ms-henglu and stephybun authored Dec 5, 2023
1 parent 83be143 commit f26bf84
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,36 @@ func TestAccKubernetesCluster_gpuInstance(t *testing.T) {
})
}

func TestAccKubernetesCluster_supportPlanKubernetesOfficial(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test")
r := KubernetesClusterResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.supportPlanKubernetesOfficial(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccKubernetesCluster_supportPlanAKSLongTermSupport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test")
r := KubernetesClusterResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.supportPlanAKSLongTermSupport(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (KubernetesClusterResource) basicAvailabilitySetConfig(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down Expand Up @@ -3154,3 +3184,63 @@ resource "azurerm_kubernetes_cluster" "test" {
}
`, data.Locations.Primary, data.RandomInteger)
}

func (KubernetesClusterResource) supportPlanKubernetesOfficial(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-aks-%[2]d"
location = "%[1]s"
}
resource "azurerm_kubernetes_cluster" "test" {
name = "acctestaks%[2]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
dns_prefix = "acctestaks%[2]d"
default_node_pool {
name = "default"
vm_size = "Standard_DS2_v2"
node_count = 1
}
identity {
type = "SystemAssigned"
}
support_plan = "KubernetesOfficial"
}
`, data.Locations.Primary, data.RandomInteger)
}

func (KubernetesClusterResource) supportPlanAKSLongTermSupport(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-aks-%[2]d"
location = "%[1]s"
}
resource "azurerm_kubernetes_cluster" "test" {
name = "acctestaks%[2]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
dns_prefix = "acctestaks%[2]d"
default_node_pool {
name = "default"
vm_size = "Standard_DS2_v2"
node_count = 1
}
identity {
type = "SystemAssigned"
}
support_plan = "AKSLongTermSupport"
sku_tier = "Premium"
}
`, data.Locations.Primary, data.RandomInteger)
}
22 changes: 22 additions & 0 deletions internal/services/containers/kubernetes_cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,7 @@ func resourceKubernetesCluster() *pluginsdk.Resource {
ValidateFunc: validation.StringInSlice([]string{
string(managedclusters.ManagedClusterSKUTierFree),
string(managedclusters.ManagedClusterSKUTierStandard),
string(managedclusters.ManagedClusterSKUTierPremium),
}, false),
},

Expand Down Expand Up @@ -1439,6 +1440,16 @@ func resourceKubernetesCluster() *pluginsdk.Resource {
},
},

"support_plan": {
Type: pluginsdk.TypeString,
Optional: true,
Default: string(managedclusters.KubernetesSupportPlanKubernetesOfficial),
ValidateFunc: validation.StringInSlice([]string{
string(managedclusters.KubernetesSupportPlanKubernetesOfficial),
string(managedclusters.KubernetesSupportPlanAKSLongTermSupport),
}, false),
},

"tags": commonschema.Tags(),

"windows_profile": {
Expand Down Expand Up @@ -1815,6 +1826,10 @@ func resourceKubernetesClusterCreate(d *pluginsdk.ResourceData, meta interface{}
parameters.Properties.DiskEncryptionSetID = utils.String(v.(string))
}

if v := d.Get("support_plan").(string); v != "" {
parameters.Properties.SupportPlan = pointer.To(managedclusters.KubernetesSupportPlan(v))
}

if ingressProfile := expandKubernetesClusterIngressProfile(d, d.Get("web_app_routing").([]interface{})); ingressProfile != nil {
parameters.Properties.IngressProfile = ingressProfile
}
Expand Down Expand Up @@ -2314,6 +2329,11 @@ func resourceKubernetesClusterUpdate(d *pluginsdk.ResourceData, meta interface{}
existing.Model.Properties.IngressProfile = expandKubernetesClusterIngressProfile(d, d.Get("web_app_routing").([]interface{}))
}

if d.HasChange("support_plan") {
updateCluster = true
existing.Model.Properties.SupportPlan = pointer.To(managedclusters.KubernetesSupportPlan(d.Get("support_plan").(string)))
}

if updateCluster {
// If Defender was explicitly disabled in a prior update then we should strip SecurityProfile.AzureDefender from the request
// body to prevent errors in cases where Defender is disabled for the entire subscription
Expand Down Expand Up @@ -2822,6 +2842,8 @@ func resourceKubernetesClusterRead(d *pluginsdk.ResourceData, meta interface{})
if err := d.Set("kube_admin_config", adminKubeConfig); err != nil {
return fmt.Errorf("setting `kube_admin_config`: %+v", err)
}

d.Set("support_plan", pointer.From(props.SupportPlan))
}

identity, err := identity.FlattenSystemOrUserAssignedMap(model.Identity)
Expand Down
4 changes: 3 additions & 1 deletion website/docs/r/kubernetes_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,14 @@ resource "azurerm_kubernetes_cluster" "example" {

!> **Note:** A migration scenario from `service_principal` to `identity` is supported. When upgrading `service_principal` to `identity`, your cluster's control plane and addon pods will switch to use managed identity, but the kubelets will keep using your configured `service_principal` until you upgrade your Node Pool.

* `sku_tier` - (Optional) The SKU Tier that should be used for this Kubernetes Cluster. Possible values are `Free`, and `Standard` (which includes the Uptime SLA). Defaults to `Free`.
* `sku_tier` - (Optional) The SKU Tier that should be used for this Kubernetes Cluster. Possible values are `Free`, `Standard` (which includes the Uptime SLA) and `Premium`. Defaults to `Free`.

-> **Note:** Whilst the AKS API previously supported the `Paid` SKU - the AKS API introduced a breaking change in API Version `2023-02-01` (used in v3.51.0 and later) where the value `Paid` must now be set to `Standard`.

* `storage_profile` - (Optional) A `storage_profile` block as defined below.

* `support_plan` - (Optional) Specifies the support plan which should be used for this Kubernetes Cluster. Possible values are `KubernetesOfficial` and `AKSLongTermSupport`. Defaults to `KubernetesOfficial`.

* `tags` - (Optional) A mapping of tags to assign to the resource.

* `web_app_routing` - (Optional) A `web_app_routing` block as defined below.
Expand Down

0 comments on commit f26bf84

Please sign in to comment.