diff --git a/.changelog/12569.txt b/.changelog/12569.txt new file mode 100644 index 0000000000..dd3f79a77b --- /dev/null +++ b/.changelog/12569.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +container: changed `google_container_cluster` to apply maintenance policy updates after upgrades during cluster update +``` \ No newline at end of file diff --git a/google-beta/services/container/resource_container_cluster.go b/google-beta/services/container/resource_container_cluster.go index b8089f6dc1..8fd5cb8c59 100644 --- a/google-beta/services/container/resource_container_cluster.go +++ b/google-beta/services/container/resource_container_cluster.go @@ -3612,35 +3612,6 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er log.Printf("[INFO] GKE cluster %s Default SNAT status has been updated", d.Id()) } - if d.HasChange("maintenance_policy") { - req := &container.SetMaintenancePolicyRequest{ - MaintenancePolicy: expandMaintenancePolicy(d, meta), - } - - updateF := func() error { - name := containerClusterFullName(project, location, clusterName) - clusterSetMaintenancePolicyCall := config.NewContainerClient(userAgent).Projects.Locations.Clusters.SetMaintenancePolicy(name, req) - if config.UserProjectOverride { - clusterSetMaintenancePolicyCall.Header().Add("X-Goog-User-Project", project) - } - op, err := clusterSetMaintenancePolicyCall.Do() - - if err != nil { - return err - } - - // Wait until it's updated - return ContainerOperationWait(config, op, project, location, "updating GKE cluster maintenance policy", userAgent, d.Timeout(schema.TimeoutUpdate)) - } - - // Call update serially. - if err := transport_tpg.LockedCall(lockKey, updateF); err != nil { - return err - } - - log.Printf("[INFO] GKE cluster %s maintenance policy has been updated", d.Id()) - } - if d.HasChange("node_locations") { azSetOldI, azSetNewI := d.GetChange("node_locations") azSetNew := azSetNewI.(*schema.Set) @@ -3908,6 +3879,36 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er } } + // Set maintenance policy after upgrade so validation will use the new versions. + if d.HasChange("maintenance_policy") { + req := &container.SetMaintenancePolicyRequest{ + MaintenancePolicy: expandMaintenancePolicy(d, meta), + } + + updateF := func() error { + name := containerClusterFullName(project, location, clusterName) + clusterSetMaintenancePolicyCall := config.NewContainerClient(userAgent).Projects.Locations.Clusters.SetMaintenancePolicy(name, req) + if config.UserProjectOverride { + clusterSetMaintenancePolicyCall.Header().Add("X-Goog-User-Project", project) + } + op, err := clusterSetMaintenancePolicyCall.Do() + + if err != nil { + return err + } + + // Wait until it's updated + return ContainerOperationWait(config, op, project, location, "updating GKE cluster maintenance policy", userAgent, d.Timeout(schema.TimeoutUpdate)) + } + + // Call update serially. + if err := transport_tpg.LockedCall(lockKey, updateF); err != nil { + return err + } + + log.Printf("[INFO] GKE cluster %s maintenance policy has been updated", d.Id()) + } + if d.HasChange("node_config") { defaultPool := "default-pool"