Skip to content

Commit 3466cd0

Browse files
cslinkamanMahendroo
authored andcommitted
Apply maintenance policy updates after upgrades so validation on maintenance policy uses the new versions. (GoogleCloudPlatform#12569)
1 parent 29bb03a commit 3466cd0

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

mmv1/third_party/terraform/services/container/resource_container_cluster.go.tmpl

+30-29
Original file line numberDiff line numberDiff line change
@@ -3654,35 +3654,6 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
36543654
log.Printf("[INFO] GKE cluster %s Default SNAT status has been updated", d.Id())
36553655
}
36563656

3657-
if d.HasChange("maintenance_policy") {
3658-
req := &container.SetMaintenancePolicyRequest{
3659-
MaintenancePolicy: expandMaintenancePolicy(d, meta),
3660-
}
3661-
3662-
updateF := func() error {
3663-
name := containerClusterFullName(project, location, clusterName)
3664-
clusterSetMaintenancePolicyCall := config.NewContainerClient(userAgent).Projects.Locations.Clusters.SetMaintenancePolicy(name, req)
3665-
if config.UserProjectOverride {
3666-
clusterSetMaintenancePolicyCall.Header().Add("X-Goog-User-Project", project)
3667-
}
3668-
op, err := clusterSetMaintenancePolicyCall.Do()
3669-
3670-
if err != nil {
3671-
return err
3672-
}
3673-
3674-
// Wait until it's updated
3675-
return ContainerOperationWait(config, op, project, location, "updating GKE cluster maintenance policy", userAgent, d.Timeout(schema.TimeoutUpdate))
3676-
}
3677-
3678-
// Call update serially.
3679-
if err := transport_tpg.LockedCall(lockKey, updateF); err != nil {
3680-
return err
3681-
}
3682-
3683-
log.Printf("[INFO] GKE cluster %s maintenance policy has been updated", d.Id())
3684-
}
3685-
36863657
if d.HasChange("node_locations") {
36873658
azSetOldI, azSetNewI := d.GetChange("node_locations")
36883659
azSetNew := azSetNewI.(*schema.Set)
@@ -3950,6 +3921,36 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
39503921
}
39513922
}
39523923

3924+
// Set maintenance policy after upgrade so validation will use the new versions.
3925+
if d.HasChange("maintenance_policy") {
3926+
req := &container.SetMaintenancePolicyRequest{
3927+
MaintenancePolicy: expandMaintenancePolicy(d, meta),
3928+
}
3929+
3930+
updateF := func() error {
3931+
name := containerClusterFullName(project, location, clusterName)
3932+
clusterSetMaintenancePolicyCall := config.NewContainerClient(userAgent).Projects.Locations.Clusters.SetMaintenancePolicy(name, req)
3933+
if config.UserProjectOverride {
3934+
clusterSetMaintenancePolicyCall.Header().Add("X-Goog-User-Project", project)
3935+
}
3936+
op, err := clusterSetMaintenancePolicyCall.Do()
3937+
3938+
if err != nil {
3939+
return err
3940+
}
3941+
3942+
// Wait until it's updated
3943+
return ContainerOperationWait(config, op, project, location, "updating GKE cluster maintenance policy", userAgent, d.Timeout(schema.TimeoutUpdate))
3944+
}
3945+
3946+
// Call update serially.
3947+
if err := transport_tpg.LockedCall(lockKey, updateF); err != nil {
3948+
return err
3949+
}
3950+
3951+
log.Printf("[INFO] GKE cluster %s maintenance policy has been updated", d.Id())
3952+
}
3953+
39533954
if d.HasChange("node_config") {
39543955

39553956
defaultPool := "default-pool"

0 commit comments

Comments
 (0)