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_node_pool - node_count, min_node, and max_node can now be set to 0 #8300

Merged
merged 14 commits into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -57,11 +57,10 @@ func resourceArmKubernetesClusterNodePool() *schema.Resource {
},

"node_count": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
// TODO: this can go to 0 after the next version of the Azure SDK
ValidateFunc: validation.IntBetween(1, 100),
Type: schema.TypeInt,
Optional: true,
Computed: true,
ValidateFunc: validation.IntBetween(0, 100),
},

"tags": tags.Schema(),
Expand Down Expand Up @@ -130,7 +129,7 @@ func resourceArmKubernetesClusterNodePool() *schema.Resource {
Type: schema.TypeInt,
Optional: true,
// NOTE: rather than setting `0` users should instead pass `null` here
ValidateFunc: validation.IntBetween(1, 100),
ValidateFunc: validation.IntBetween(0, 100),
},

"node_labels": {
Expand Down Expand Up @@ -347,7 +346,7 @@ func resourceArmKubernetesClusterNodePoolCreate(d *schema.ResourceData, meta int
return fmt.Errorf("`max_count` must be configured when `enable_auto_scaling` is set to `true`")
}

if minCount > 0 {
if minCount >= 0 {
profile.MinCount = utils.Int32(int32(minCount))
} else {
return fmt.Errorf("`min_count` must be configured when `enable_auto_scaling` is set to `true`")
Expand Down Expand Up @@ -493,9 +492,6 @@ func resourceArmKubernetesClusterNodePoolUpdate(d *schema.ResourceData, meta int
if maxCount == 0 {
return fmt.Errorf("`max_count` must be configured when `enable_auto_scaling` is set to `true`")
}
if minCount == 0 {
return fmt.Errorf("`min_count` must be configured when `enable_auto_scaling` is set to `true`")
}

if minCount > maxCount {
return fmt.Errorf("`max_count` must be >= `min_count`")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var kubernetesNodePoolTests = map[string]func(t *testing.T){
"virtualNetworkManual": testAccAzureRMKubernetesClusterNodePool_virtualNetworkManual,
"windows": testAccAzureRMKubernetesClusterNodePool_windows,
"windowsAndLinux": testAccAzureRMKubernetesClusterNodePool_windowsAndLinux,
"zeroSize": testAccAzureRMKubernetesClusterNodePool_zeroSize,
}

func TestAccAzureRMKubernetesClusterNodePool_autoScale(t *testing.T) {
Expand Down Expand Up @@ -113,7 +114,7 @@ func testAccAzureRMKubernetesClusterNodePool_autoScaleUpdate(t *testing.T) {
},
data.ImportStep(),
{
Config: testAccAzureRMKubernetesClusterNodePool_autoScaleNodeCountConfig(data, 1, 3),
Config: testAccAzureRMKubernetesClusterNodePool_autoScaleNodeCountConfig(data, 0, 3),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMKubernetesNodePoolExists(data.ResourceName),
),
Expand Down Expand Up @@ -729,6 +730,30 @@ func testAccAzureRMKubernetesClusterNodePool_windowsAndLinux(t *testing.T) {
})
}

func TestAccAzureRMKubernetesClusterNodePool_zeroSize(t *testing.T) {
checkIfShouldRunTestsIndividually(t)
testAccAzureRMKubernetesClusterNodePool_zeroSize(t)
}

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

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMKubernetesClusterNodePoolDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMKubernetesClusterNodePool_zeroSizeConfig(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMKubernetesNodePoolExists(data.ResourceName),
),
},
data.ImportStep(),
},
})
}

func testCheckAzureRMKubernetesClusterNodePoolDestroy(s *terraform.State) error {
client := acceptance.AzureProvider.Meta().(*clients.Client).Containers.AgentPoolsClient
ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext
Expand Down Expand Up @@ -1576,3 +1601,24 @@ resource "azurerm_kubernetes_cluster" "test" {
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
}

func testAccAzureRMKubernetesClusterNodePool_zeroSizeConfig(data acceptance.TestData) string {
template := testAccAzureRMKubernetesClusterNodePool_templateConfig(data)
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

%s

resource "azurerm_kubernetes_cluster_node_pool" "test" {
name = "internal"
kubernetes_cluster_id = azurerm_kubernetes_cluster.test.id
vm_size = "Standard_DS2_v2"
enable_auto_scaling = true
min_count = 0
max_count = 3
node_count = 0
}
`, template)
}