Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_kubernetes_cluster - support for the support_plan property #23970

Merged
merged 6 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,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 @@ -3149,3 +3179,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 @@ -1397,6 +1397,7 @@ func resourceKubernetesCluster() *pluginsdk.Resource {
ValidateFunc: validation.StringInSlice([]string{
string(managedclusters.ManagedClusterSKUTierFree),
string(managedclusters.ManagedClusterSKUTierStandard),
string(managedclusters.ManagedClusterSKUTierPremium),
}, false),
},

Expand Down Expand Up @@ -1440,6 +1441,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 @@ -1817,6 +1828,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 @@ -2317,6 +2332,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 @@ -2809,6 +2829,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
Loading