@@ -96,29 +96,47 @@ func resourceContainerCluster() *schema.Resource {
96
96
},
97
97
},
98
98
99
+ "location" : {
100
+ Type : schema .TypeString ,
101
+ Optional : true ,
102
+ Computed : true ,
103
+ ForceNew : true ,
104
+ ConflictsWith : []string {"zone" , "region" },
105
+ },
106
+
99
107
"region" : {
100
108
Type : schema .TypeString ,
101
109
Optional : true ,
102
110
Computed : true ,
103
111
ForceNew : true ,
104
- ConflictsWith : []string {"zone" },
112
+ Deprecated : "Use location instead" ,
113
+ ConflictsWith : []string {"zone" , "location" },
105
114
},
106
115
107
116
"zone" : {
108
117
Type : schema .TypeString ,
109
118
Optional : true ,
110
119
Computed : true ,
111
120
ForceNew : true ,
112
- ConflictsWith : []string {"region" },
121
+ Deprecated : "Use location instead" ,
122
+ ConflictsWith : []string {"region" , "location" },
113
123
},
114
124
115
- "additional_zones " : {
125
+ "node_locations " : {
116
126
Type : schema .TypeSet ,
117
127
Optional : true ,
118
128
Computed : true ,
119
129
Elem : & schema.Schema {Type : schema .TypeString },
120
130
},
121
131
132
+ "additional_zones" : {
133
+ Type : schema .TypeSet ,
134
+ Optional : true ,
135
+ Computed : true ,
136
+ Deprecated : "Use node_locations instead" ,
137
+ Elem : & schema.Schema {Type : schema .TypeString },
138
+ },
139
+
122
140
"addons_config" : {
123
141
Type : schema .TypeList ,
124
142
Optional : true ,
@@ -666,14 +684,29 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
666
684
}
667
685
}
668
686
669
- if v , ok := d .GetOk ("additional_zones " ); ok {
687
+ if v , ok := d .GetOk ("node_locations " ); ok {
670
688
locationsSet := v .(* schema.Set )
671
689
if locationsSet .Contains (location ) {
672
- return fmt .Errorf ("additional_zones should not contain the original 'zone'" )
690
+ return fmt .Errorf ("when using a multi-zonal cluster, additional_zones should not contain the original 'zone'" )
691
+ }
692
+
693
+ // GKE requires a full list of node locations
694
+ // but when using a multi-zonal cluster our schema only asks for the
695
+ // additional zones, so append the cluster location if it's a zone
696
+ if isZone (location ) {
697
+ locationsSet .Add (location )
698
+ }
699
+ cluster .Locations = convertStringSet (locationsSet )
700
+ } else if v , ok := d .GetOk ("additional_zones" ); ok {
701
+ locationsSet := v .(* schema.Set )
702
+ if locationsSet .Contains (location ) {
703
+ return fmt .Errorf ("when using a multi-zonal cluster, additional_zones should not contain the original 'zone'" )
673
704
}
705
+
706
+ // GKE requires a full list of node locations
707
+ // but when using a multi-zonal cluster our schema only asks for the
708
+ // additional zones, so append the cluster location if it's a zone
674
709
if isZone (location ) {
675
- // GKE requires a full list of locations (including the original zone),
676
- // but our schema only asks for additional zones, so append the original.
677
710
locationsSet .Add (location )
678
711
}
679
712
cluster .Locations = convertStringSet (locationsSet )
@@ -804,10 +837,17 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro
804
837
if err := d .Set ("network_policy" , flattenNetworkPolicy (cluster .NetworkPolicy )); err != nil {
805
838
return err
806
839
}
807
- d .Set ("zone" , cluster .Zone )
840
+
841
+ d .Set ("location" , cluster .Location )
842
+ if isZone (cluster .Location ) {
843
+ d .Set ("zone" , cluster .Location )
844
+ } else {
845
+ d .Set ("region" , cluster .Location )
846
+ }
808
847
809
848
locations := schema .NewSet (schema .HashString , convertStringArrToInterface (cluster .Locations ))
810
849
locations .Remove (cluster .Zone ) // Remove the original zone since we only store additional zones
850
+ d .Set ("node_locations" , locations )
811
851
d .Set ("additional_zones" , locations )
812
852
813
853
d .Set ("endpoint" , cluster .Endpoint )
@@ -975,6 +1015,9 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
975
1015
d .SetPartial ("maintenance_policy" )
976
1016
}
977
1017
1018
+ // we can only ever see a change to one of additional_zones and node_locations; because
1019
+ // thy conflict with each other and are each computed, Terraform will suppress the diff
1020
+ // on one of them even when migrating from one to the other.
978
1021
if d .HasChange ("additional_zones" ) {
979
1022
azSetOldI , azSetNewI := d .GetChange ("additional_zones" )
980
1023
azSetNew := azSetNewI .(* schema.Set )
@@ -996,7 +1039,7 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
996
1039
},
997
1040
}
998
1041
999
- updateF := updateFunc (req , "updating GKE cluster locations" )
1042
+ updateF := updateFunc (req , "updating GKE cluster node locations" )
1000
1043
// Call update serially.
1001
1044
if err := lockedCall (lockKey , updateF ); err != nil {
1002
1045
return err
@@ -1012,16 +1055,63 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
1012
1055
},
1013
1056
}
1014
1057
1015
- updateF := updateFunc (req , "updating GKE cluster locations" )
1058
+ updateF := updateFunc (req , "updating GKE cluster node locations" )
1016
1059
// Call update serially.
1017
1060
if err := lockedCall (lockKey , updateF ); err != nil {
1018
1061
return err
1019
1062
}
1020
1063
}
1021
1064
1022
- log .Printf ("[INFO] GKE cluster %s locations have been updated to %v" , d .Id (), azSet .List ())
1065
+ log .Printf ("[INFO] GKE cluster %s node locations have been updated to %v" , d .Id (), azSet .List ())
1023
1066
1024
1067
d .SetPartial ("additional_zones" )
1068
+ } else if d .HasChange ("node_locations" ) {
1069
+ azSetOldI , azSetNewI := d .GetChange ("node_locations" )
1070
+ azSetNew := azSetNewI .(* schema.Set )
1071
+ azSetOld := azSetOldI .(* schema.Set )
1072
+ if azSetNew .Contains (location ) {
1073
+ return fmt .Errorf ("for multi-zonal clusters, node_locations should not contain the primary 'zone'" )
1074
+ }
1075
+ // Since we can't add & remove zones in the same request, first add all the
1076
+ // zones, then remove the ones we aren't using anymore.
1077
+ azSet := azSetOld .Union (azSetNew )
1078
+
1079
+ if isZone (location ) {
1080
+ azSet .Add (location )
1081
+ }
1082
+
1083
+ req := & containerBeta.UpdateClusterRequest {
1084
+ Update : & containerBeta.ClusterUpdate {
1085
+ DesiredLocations : convertStringSet (azSet ),
1086
+ },
1087
+ }
1088
+
1089
+ updateF := updateFunc (req , "updating GKE cluster node locations" )
1090
+ // Call update serially.
1091
+ if err := lockedCall (lockKey , updateF ); err != nil {
1092
+ return err
1093
+ }
1094
+
1095
+ if isZone (location ) {
1096
+ azSetNew .Add (location )
1097
+ }
1098
+ if ! azSet .Equal (azSetNew ) {
1099
+ req = & containerBeta.UpdateClusterRequest {
1100
+ Update : & containerBeta.ClusterUpdate {
1101
+ DesiredLocations : convertStringSet (azSetNew ),
1102
+ },
1103
+ }
1104
+
1105
+ updateF := updateFunc (req , "updating GKE cluster node locations" )
1106
+ // Call update serially.
1107
+ if err := lockedCall (lockKey , updateF ); err != nil {
1108
+ return err
1109
+ }
1110
+ }
1111
+
1112
+ log .Printf ("[INFO] GKE cluster %s node locations have been updated to %v" , d .Id (), azSet .List ())
1113
+
1114
+ d .SetPartial ("node_locations" )
1025
1115
}
1026
1116
1027
1117
if d .HasChange ("enable_legacy_abac" ) {
@@ -1796,7 +1886,7 @@ func resourceContainerClusterStateImporter(d *schema.ResourceData, meta interfac
1796
1886
location = parts [1 ]
1797
1887
clusterName = parts [2 ]
1798
1888
default :
1799
- return nil , fmt .Errorf ("Invalid container cluster specifier. Expecting {zone }/{name} or {project}/{zone }/{name}" )
1889
+ return nil , fmt .Errorf ("Invalid container cluster specifier. Expecting {location }/{name} or {project}/{location }/{name}" )
1800
1890
}
1801
1891
1802
1892
if len (project ) > 0 {
@@ -1809,6 +1899,7 @@ func resourceContainerClusterStateImporter(d *schema.ResourceData, meta interfac
1809
1899
}
1810
1900
}
1811
1901
1902
+ d .Set ("location" , location )
1812
1903
if isZone (location ) {
1813
1904
d .Set ("zone" , location )
1814
1905
} else {
0 commit comments