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

AKS - allow in-place upgrade from free to paid sku_tier #7927

Merged
merged 3 commits into from
Jul 28, 2020
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 @@ -8,6 +8,7 @@ import (
"time"

"github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2020-03-01/containerservice"
"github.com/hashicorp/terraform-plugin-sdk/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
Expand Down Expand Up @@ -38,6 +39,13 @@ func resourceArmKubernetesCluster() *schema.Resource {
return err
}),

CustomizeDiff: customdiff.Sequence(
// Downgrade from Paid to Free is not supported and requires rebuild to apply
customdiff.ForceNewIfChange("sku_tier", func(old, new, meta interface{}) bool {
return new == "Free"
}),
),

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(90 * time.Minute),
Read: schema.DefaultTimeout(5 * time.Minute),
Expand Down Expand Up @@ -510,11 +518,11 @@ func resourceArmKubernetesCluster() *schema.Resource {
Type: schema.TypeString,
Optional: true,
// @tombuildsstuff (2020-05-29) - Preview limitations:
// * Currently, cannot convert as existing cluster to enable the Uptime SLA.
// * Currently, there is no way to remove Uptime SLA from an AKS cluster after creation with it enabled.
// * Private clusters aren't currently supported.
ForceNew: true,
Default: string(containerservice.Free),
// @jackofallops (2020-07-21) - Update:
// * sku_tier can now be upgraded in place, downgrade requires rebuild
Default: string(containerservice.Free),
ValidateFunc: validation.StringInSlice([]string{
string(containerservice.Free),
string(containerservice.Paid),
Expand Down Expand Up @@ -1032,6 +1040,11 @@ func resourceArmKubernetesClusterUpdate(d *schema.ResourceData, meta interface{}
existing.Identity = expandKubernetesClusterManagedClusterIdentity(managedClusterIdentityRaw)
}

if d.HasChange("sku_tier") {
updateCluster = true
existing.Sku.Tier = containerservice.ManagedClusterSKUTier(d.Get("sku_tier").(string))
}

if updateCluster {
log.Printf("[DEBUG] Updating the Kubernetes Cluster %q (Resource Group %q)..", id.Name, id.ResourceGroup)
future, err := clusterClient.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, existing)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,37 @@ func testAccAzureRMKubernetesCluster_nodeResourceGroup(t *testing.T) {
})
}

func TestAccAzureRMKubernetesCluster_upgradeSkuTier(t *testing.T) {
checkIfShouldRunTestsIndividually(t)
testAccAzureRMKubernetesCluster_upgradeSkuTier(t)
}

func testAccAzureRMKubernetesCluster_upgradeSkuTier(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMKubernetesClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMKubernetesCluster_freeSkuConfig(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMKubernetesClusterExists(data.ResourceName),
),
},
data.ImportStep(),
{
Config: testAccAzureRMKubernetesCluster_paidSkuConfig(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMKubernetesClusterExists(data.ResourceName),
),
},
data.ImportStep(),
},
})
}

func TestAccAzureRMKubernetesCluster_paidSku(t *testing.T) {
checkIfShouldRunTestsIndividually(t)
testAccAzureRMKubernetesCluster_paidSku(t)
Expand Down Expand Up @@ -862,6 +893,39 @@ resource "azurerm_kubernetes_cluster" "test" {
`, data.RandomInteger, location, data.RandomInteger, data.RandomInteger)
}

func testAccAzureRMKubernetesCluster_freeSkuConfig(data acceptance.TestData) string {
// @tombuildsstuff (2020-05-29) - this is only supported in a handful of regions
// whilst in Preview - hard-coding for now
location := "westus2" // TODO: data.Locations.Primary
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-aks-%d"
location = "%s"
}

resource "azurerm_kubernetes_cluster" "test" {
name = "acctestaks%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
dns_prefix = "acctestaks%d"

default_node_pool {
name = "default"
node_count = 1
vm_size = "Standard_DS2_v2"
}

identity {
type = "SystemAssigned"
}
}
`, data.RandomInteger, location, data.RandomInteger, data.RandomInteger)
}

func testAccAzureRMKubernetesCluster_tagsConfig(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/kubernetes_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ In addition, one of either `identity` or `service_principal` blocks must be spec

-> **NOTE:** One of either `identity` or `service_principal` must be specified.

* `sku_tier` - (Optional) The SKU Tier that should be used for this Kubernetes Cluster. Changing this forces a new resource to be created. Possible values are `Free` and `Paid` (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` and `Paid` (which includes the Uptime SLA). Defaults to `Free`.

~> **Note:** This functionality is in Preview and has [several limitations](https://docs.microsoft.com/en-us/azure/aks/uptime-sla).
~> **Note:** It is currently possible to upgrade in place from `Free` to `Paid`. However, changing this value from `Paid` to `Free` will force a new resource to be created.

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

Expand Down