fix: handle null secondary_ip_range in cluster_alias_ranges_cidr#2581
fix: handle null secondary_ip_range in cluster_alias_ranges_cidr#2581raman1236 wants to merge 1 commit into
Conversation
Fixes terraform-google-modules#564 When using add_cluster_firewall_rules=true and performing terraform destroy, or when the subnetwork data source returns null secondary_ip_range, Terraform fails with 'A null value cannot be used as the collection in a for expression.' This fix uses coalesce() to default null secondary_ip_range to an empty list, preventing the error during destroy operations and edge cases where the subnetwork might not have secondary IP ranges available. Affected modules: - main root module - beta-private-cluster-update-variant - private-cluster - beta-public-cluster - beta-private-cluster - beta-autopilot-public-cluster - beta-autopilot-private-cluster - private-cluster-update-variant - beta-public-cluster-update-variant
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request enhances several GKE modules by adding the coalesce function to handle potential null values in secondary_ip_range and refactoring logging_config logic to use a new logging_config_is_set local variable. These changes ensure more reliable resource creation and clearer conditional logic for logging components. I have no feedback to provide.
Description
Fixes #564
When using
add_cluster_firewall_rules=trueand performingterraform destroy, or when the subnetwork data source returns nullsecondary_ip_range, Terraform fails with:Root Cause
The
cluster_alias_ranges_cidrlocal iterates overdata.google_compute_subnetwork.gke_subnetwork[0].secondary_ip_rangedirectly. During destroy operations (or certain edge cases), this value can benullinstead of an empty list, causing the error.Solution
This fix uses
coalesce()to default nullsecondary_ip_rangeto an empty list:Affected Modules
Applied the fix consistently across all modules that use this pattern:
Testing
secondary_ip_rangeis not null, behavior is identical