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 - min_count can be updated when enable_auto_scaling is set to true #8619

Merged
merged 6 commits into from
Oct 22, 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 @@ -260,7 +260,7 @@ func ExpandDefaultNodePool(d *schema.ResourceData) (*[]containerservice.ManagedC
if minCount > 0 {
profile.MinCount = utils.Int32(int32(minCount))

if minCount > count {
if minCount > count && d.IsNewResource() {
return nil, fmt.Errorf("`node_count`(%d) must be equal to or greater than `min_count`(%d) when `enable_auto_scaling` is set to `true`", count, minCount)
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

var kubernetesUpgradeTests = map[string]func(t *testing.T){
"UpgradeAutoScaleMinCount": testAccAzureRMKubernetesCluster_upgradeAutoScaleMinCount,
"upgradeControlPlane": testAccAzureRMKubernetesCluster_upgradeControlPlane,
"upgradeControlPlaneAndDefaultNodePoolTogether": testAccAzureRMKubernetesCluster_upgradeControlPlaneAndDefaultNodePoolTogether,
"upgradeControlPlaneAndDefaultNodePoolTwoPhase": testAccAzureRMKubernetesCluster_upgradeControlPlaneAndDefaultNodePoolTwoPhase,
Expand All @@ -18,6 +19,37 @@ var kubernetesUpgradeTests = map[string]func(t *testing.T){
"upgradeCustomNodePoolBeforeControlPlaneFails": testAccAzureRMKubernetesCluster_upgradeCustomNodePoolBeforeControlPlaneFails,
}

func TestAccAzureRMKubernetesCluster_upgradeAutoScaleMinCount(t *testing.T) {
checkIfShouldRunTestsIndividually(t)
testAccAzureRMKubernetesCluster_upgradeAutoScaleMinCount(t)
}

func testAccAzureRMKubernetesCluster_upgradeAutoScaleMinCount(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_upgradeAutoScaleMinCountConfig(data, olderKubernetesVersion, 3, 8),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMKubernetesClusterExists(data.ResourceName),
),
},
data.ImportStep(),
{
Config: testAccAzureRMKubernetesCluster_upgradeAutoScaleMinCountConfig(data, olderKubernetesVersion, 4, 8),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMKubernetesClusterExists(data.ResourceName),
),
},
data.ImportStep(),
},
})
}

func TestAccAzureRMKubernetesCluster_upgradeControlPlane(t *testing.T) {
checkIfShouldRunTestsIndividually(t)
testAccAzureRMKubernetesCluster_upgradeControlPlane(t)
Expand Down Expand Up @@ -326,3 +358,36 @@ resource "azurerm_kubernetes_cluster_node_pool" "test" {
}
`, template, customNodePoolVersion)
}

func testAccAzureRMKubernetesCluster_upgradeAutoScaleMinCountConfig(data acceptance.TestData, controlPlaneVersion string, minCount int, maxCount int) string {
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"
kubernetes_version = %q

default_node_pool {
name = "default"
vm_size = "Standard_DS2_v2"
enable_auto_scaling = true
min_count = %d
max_count = %d
}

identity {
type = "SystemAssigned"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, controlPlaneVersion, minCount, maxCount)
}