mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-06 02:02:43 +00:00
Make sure that additional zones are added-then-removed instead of all at once. (#1354)
This commit is contained in:
parent
b70db7b40a
commit
92d98fc8e1
|
@ -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")
|
||||
|
|
|
@ -1364,7 +1364,6 @@ resource "google_container_cluster" "with_additional_zones" {
|
|||
|
||||
additional_zones = [
|
||||
"us-central1-f",
|
||||
"us-central1-b",
|
||||
"us-central1-c",
|
||||
]
|
||||
}`, clusterName)
|
||||
|
|
Loading…
Reference in New Issue
Block a user