From f16989dec63054441d2b7782cbb25ab78061e6c5 Mon Sep 17 00:00:00 2001 From: Cameron Thornton Date: Wed, 29 Jul 2026 13:45:43 -0500 Subject: [PATCH] container: fix stale IGM cache in google_container_node_pool when resizing or ignore_node_count_changes is active Fixes https://github.com/hashicorp/terraform-provider-google/issues/27966 This PR fixes a bug where google_container_node_pool and google_container_cluster failed to invalidate their Instance Group Manager cache when a resize occurred or when ignore_node_count_changes was active. ```release-note:bug container: fixed a bug where `google_container_node_pool` and `google_container_cluster` failed to invalidate their Instance Group Manager cache when a resize occurred or when `ignore_node_count_changes` was active ``` --- .../resource_container_node_pool.go.tmpl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/mmv1/third_party/terraform/services/container/resource_container_node_pool.go.tmpl b/mmv1/third_party/terraform/services/container/resource_container_node_pool.go.tmpl index e808ce486cb7..4d42ac6e4228 100644 --- a/mmv1/third_party/terraform/services/container/resource_container_node_pool.go.tmpl +++ b/mmv1/third_party/terraform/services/container/resource_container_node_pool.go.tmpl @@ -158,6 +158,19 @@ func (instanceGroupManagerCache *instanceGroupManagerCache) needsRefresh(fullyQu return time.Since(igm.updateTime) > instanceGroupManagerCache.ttl } +// invalidateItem removes a specific Instance Group Manager from the cache by its URL. +// This is called when a node pool is resized or when ignore_node_count_changes is active, +// ensuring that stale cached target sizes are not served on subsequent lookups. +func (instanceGroupManagerCache *instanceGroupManagerCache) invalidateItem(igmUrl string) { + instanceGroupManagerCache.mutex.Lock() + defer instanceGroupManagerCache.mutex.Unlock() + + matches := instanceGroupManagerURL.FindStringSubmatch(igmUrl) + if len(matches) >= 4 { + delete(instanceGroupManagerCache.instanceGroupManagers, matches[0]) + } +} + // We need to set ttl to 0 to disable caching in VCR testing. // This ensure all NP/MIG LIST requests are made consistently, // preventing non-deterministic behavior that would break VCR. @@ -1524,6 +1537,7 @@ func flattenNodePool(d *schema.ResourceData, config *transport_tpg.Config, np *c // or leave them empty. Passing the API URLs to igmUrls at least populates them for basic usage. for _, url := range np.InstanceGroupUrls { igmUrls = append(igmUrls, url) + igmCache.invalidateItem(url) } } else { for _, url := range np.InstanceGroupUrls { @@ -1867,6 +1881,11 @@ func nodePoolUpdate(d *schema.ResourceData, meta interface{}, nodePoolInfo *Node if err := retryWhileIncompatibleOperation(timeout, npLockKey, updateF); err != nil { return err } + if urls, ok := d.GetOk(prefix + "instance_group_urls"); ok { + for _, u := range urls.([]interface{}) { + igmCache.invalidateItem(u.(string)) + } + } log.Printf("[INFO] GKE node pool %s size has been updated to %d", name, newSize) }