Fix(google/gke): require node_count or autoscaling on node pools

What does this MR do and why?

A minimal node_pools entry inherited node_count = 0 with autoscaling unset, producing a node pool with no nodes. Nothing could be scheduled, so terraform apply waited on the operator Deployment rollout until it failed with an opaque context deadline exceeded.

This adds a validation to node_pools that rejects a pool configuring neither, with a message naming the actual problem.

The issue offers "default node_count to 1, and/or add a validation". I went with validation only, because changing the default would regress autoscaling users.

main.tf passes node_count = each.value.node_count > 0 ? each.value.node_count : null. Zero is the sentinel that hands sizing to the autoscaling block. Defaulting to 1 would send a node_count alongside autoscaling for every pool that configures only autoscaling.

It also keeps README.md untouched: terraform-docs does not render validation blocks, but it does render defaults.

One thing worth a close look: the test fixture was an instance of the same bug.

In gke_test.go, vpc and autoscaling were nested inside node_pools rather than beside it. Terraform discards attributes absent from an object type constraint, so each silently became a node pool with everything defaulted — node_count = 0, autoscaling = null. TestGKE asserted all three, so the suite has been planning three zero-node pools.

Both now sit at the top level, matching the module's own vpc and autoscaling variables at variables.tf:157 and :79, and TestGKE expects the one real pool. I am reading that nesting as accidental — please confirm, since it is the part of this MR that changes existing expectations.

Differences

Before: node_pools = { default = {} } planned successfully and created a pool with zero nodes. The failure surfaced much later as context deadline exceeded while waiting on the operator rollout, pointing at the operator rather than the config.

After: the same config fails immediately at variable validation, naming the pool requirement directly. Pools with node_count > 0, or with autoscaling configured, are unaffected.

How to set up and validate locally

Variable validation is evaluated before the provider needs credentials, so these two can be checked without GCP access:

go test ./modules/google/gke/ -run 'TestGKEPlanErrors/node-pool'
terraform fmt -check modules/google/gke/

node-pool-without-nodes-or-autoscaling trips the new rule; node-pool-with-autoscaling-and-no-node-count does not.

Full plan assertions (TestGKE) need real GCP credentials and fail locally with could not find default credentials, so those run in CI.

Edited by Jeston Singh

Merge request reports

Loading
Loading