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

fix autoscaling block #877

Merged
merged 3 commits into from
Oct 12, 2022
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
11 changes: 7 additions & 4 deletions modules/gke-nodepool/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ resource "google_container_node_pool" "nodepool" {

dynamic "autoscaling" {
for_each = (
try(var.nodepool_config.autoscaling.use_total_nodes, false) ? [] : [""]
try(var.nodepool_config.autoscaling, null) != null
&&
!try(var.nodepool_config.autoscaling.use_total_nodes, false)
? [""] : []
)
content {
location_policy = try(var.nodepool_config.autoscaling.location_policy, null)
Expand All @@ -94,9 +97,9 @@ resource "google_container_node_pool" "nodepool" {
try(var.nodepool_config.autoscaling.use_total_nodes, false) ? [""] : []
)
content {
location_policy = try(var.nodepool_config.autoscaling.location_policy, null)
max_node_count = try(var.nodepool_config.autoscaling.max_node_count, null)
min_node_count = try(var.nodepool_config.autoscaling.min_node_count, null)
location_policy = try(var.nodepool_config.autoscaling.location_policy, null)
total_max_node_count = try(var.nodepool_config.autoscaling.max_node_count, null)
total_min_node_count = try(var.nodepool_config.autoscaling.min_node_count, null)
}
}

Expand Down
17 changes: 17 additions & 0 deletions tests/modules/gke_nodepool/test_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def test_defaults(plan_runner):
"Test resources created with variable defaults."
_, resources = plan_runner()
assert len(resources) == 1
assert resources[0]['values']['autoscaling'] == []


def test_service_account(plan_runner):
Expand All @@ -34,6 +35,22 @@ def test_nodepool_config(plan_runner):
upgrade_settings = { max_surge = 3, max_unavailable = 3 }
}'''
_, resources = plan_runner(nodepool_config=nodepool_config)
assert resources[0]['values']['autoscaling'] == [{
'location_policy': None,
'max_node_count': None,
'min_node_count': None,
'total_max_node_count': 3,
'total_min_node_count': None
}]
nodepool_config = '{ autoscaling = { max_node_count = 3} }'
_, resources = plan_runner(nodepool_config=nodepool_config)
assert resources[0]['values']['autoscaling'] == [{
'location_policy': None,
'max_node_count': 3,
'min_node_count': None,
'total_max_node_count': None,
'total_min_node_count': None
}]


def test_node_config(plan_runner):
Expand Down