-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
TL;DR
Currently, the private-cluster
module forces the creation of a default node pool even when node_pools = []
is specified. This prevents us to manage the node pools externally with dedicated node-pool modules.
Problem statement
Currently, the private-cluster
module forces the creation of a default node pool even when node_pools = []
is specified. This prevents us to manage the node pools externally with dedicated node-pool modules.
The issue happens because:
- The
node_pools
variables defaults to[{name = "default-node-pool"}]
[ref] - The
node_pool
block in the cluster resource is not conditional [ref] - When
node_pools = []
is set, the module still tries to accessvar.node_pool[0]
causing index errors [ref]
Detailed design:
- Update
variables.tf
:
variable "node_pools" {
default = [] # changed from {name = "default-node-pool"}
...
- Create a conditional to the
node_pool
block:
dynamic "node_pool" {
for_each = length(var.node_pools) > 0 ? [1] : []
content {
name = "default-pool"
initial_node_count = var.initial_node_count
# ... rest of the config
}
}
- Handle an edge case in the
main.tf
[ref] :
...
cluster_name_parts_from_nodepool = length(values(google_container_node_pool.pools)) > 0 ? split("/", element(values(google_container_node_pool.pools)[*].id, 0)) : []
cluster_name_computed = length(local.cluster_name_parts_from_nodepool) > 0 ? element(local.cluster_name_parts_from_nodepool, length(local.cluster_name_parts_from_nodepool) - 3)
...
I have tested the code above, and I was able to create a cluster with no default node pool.
Would the maintainers be open to a pull request implementing this feature? I'm happy to submit a clean PR with the changes, and update the current documentation.
Additional information
No response
Edit
The solution above is not backward compatible.
The correct way to implement is to not change the variable default, and use the conditional:
for_each = length(var.node_pools) == 0 ? [] : [1]
In the pool-node
block.