Make sure that additional zones are added-then-removed instead of all at once. (#1354)

This commit is contained in:
Nathan McKinley 2018-04-18 17:29:07 -07:00 committed by GitHub
parent b70db7b40a
commit 92d98fc8e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 3 deletions

View File

@ -998,11 +998,17 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
}
if d.HasChange("additional_zones") {
azSet := d.Get("additional_zones").(*schema.Set)
if azSet.Contains(location) {
azSetOldI, azSetNewI := d.GetChange("additional_zones")
azSetNew := azSetNewI.(*schema.Set)
azSetOld := azSetOldI.(*schema.Set)
if azSetNew.Contains(location) {
return fmt.Errorf("additional_zones should not contain the original 'zone'")
}
// Since we can't add & remove zones in the same request, first add all the
// zones, then remove the ones we aren't using anymore.
azSet := azSetOld.Union(azSetNew)
azSet.Add(location)
req := &container.UpdateClusterRequest{
Update: &container.ClusterUpdate{
DesiredLocations: convertStringSet(azSet),
@ -1015,6 +1021,21 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
return err
}
azSetNew.Add(location)
if !azSet.Equal(azSetNew) {
req = &container.UpdateClusterRequest{
Update: &container.ClusterUpdate{
DesiredLocations: convertStringSet(azSetNew),
},
}
updateF := updateFunc(req, "updating GKE cluster locations")
// Call update serially.
if err := lockedCall(lockKey, updateF); err != nil {
return err
}
}
log.Printf("[INFO] GKE cluster %s locations have been updated to %v", d.Id(), azSet.List())
d.SetPartial("additional_zones")

View File

@ -1364,7 +1364,6 @@ resource "google_container_cluster" "with_additional_zones" {
additional_zones = [
"us-central1-f",
"us-central1-b",
"us-central1-c",
]
}`, clusterName)