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 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 @@ -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 @@ -103,10 +102,9 @@ func resourceArmKubernetesClusterNodePool() *schema.Resource {
},

"max_count": {
Type: schema.TypeInt,
Optional: true,
// NOTE: rather than setting `0` users should instead pass `null` here
ValidateFunc: validation.IntBetween(1, 100),
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(0, 100),
},

"max_pods": {
Expand All @@ -130,7 +128,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 @@ -341,19 +339,19 @@ func resourceArmKubernetesClusterNodePoolCreate(d *schema.ResourceData, meta int
profile.Count = utils.Int32(int32(minCount))
}

if maxCount > 0 {
if maxCount >= 0 {
profile.MaxCount = utils.Int32(int32(maxCount))
} else {
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`")
}

if minCount > maxCount {
if minCount >= maxCount {
return fmt.Errorf("`max_count` must be >= `min_count`")
}
} else if minCount > 0 || maxCount > 0 {
Expand Down Expand Up @@ -493,11 +491,8 @@ 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 {
if minCount >= maxCount {
return fmt.Errorf("`max_count` must be >= `min_count`")
}
} else {
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)
}
8 changes: 4 additions & 4 deletions website/docs/r/kubernetes_cluster_node_pool.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ The following arguments are supported:

If `enable_auto_scaling` is set to `true`, then the following fields can also be configured:

* `max_count` - (Required) The maximum number of nodes which should exist within this Node Pool. Valid values are between `1` and `100` and must be greater than or equal to `min_count`.
* `max_count` - (Required) The maximum number of nodes which should exist within this Node Pool. Valid values are between `0` and `100` and must be greater than or equal to `min_count`.

* `min_count` - (Required) The minimum number of nodes which should exist within this Node Pool. Valid values are between `1` and `100` and must be less than or equal to `max_count`.
* `min_count` - (Required) The minimum number of nodes which should exist within this Node Pool. Valid values are between `0` and `100` and must be less than or equal to `max_count`.

* `node_count` - (Optional) The initial number of nodes which should exist within this Node Pool. Valid values are between `1` and `100` and must be a value in the range `min_count` - `max_count`.
* `node_count` - (Optional) The initial number of nodes which should exist within this Node Pool. Valid values are between `0` and `100` and must be a value in the range `min_count` - `max_count`.

-> **NOTE:** If you're specifying an initial number of nodes you may wish to use [Terraform's `ignore_changes` functionality](https://www.terraform.io/docs/configuration/resources.html#ignore_changes) to ignore changes to this field.

If `enable_auto_scaling` is set to `false`, then the following fields can also be configured:

* `node_count` - (Required) The number of nodes which should exist within this Node Pool. Valid values are between `1` and `100`.
* `node_count` - (Required) The number of nodes which should exist within this Node Pool. Valid values are between `0` and `100`.

## Attributes Reference

Expand Down