@@ -184,17 +184,22 @@ func NodeIDToZoneAndName(id string) (string, string, error) {
184
184
}
185
185
186
186
func GetRegionFromZones (zones []string ) (string , error ) {
187
+ const tpcPrefix = "u"
187
188
regions := sets.String {}
188
189
if len (zones ) < 1 {
189
190
return "" , fmt .Errorf ("no zones specified" )
190
191
}
191
192
for _ , zone := range zones {
192
193
// Zone expected format {locale}-{region}-{zone}
194
+ // TPC zone expected format is u-{}-{}-{}, e.g. u-europe-central2-a. See go/tpc-region-naming.
193
195
splitZone := strings .Split (zone , "-" )
194
- if len (splitZone ) != 3 {
195
- return "" , fmt .Errorf ("zone in unexpected format, expected: {locale}-{region}-{zone}, got: %v" , zone )
196
+ if len (splitZone ) == 3 {
197
+ regions .Insert (strings .Join (splitZone [0 :2 ], "-" ))
198
+ } else if len (splitZone ) == 4 && splitZone [0 ] == tpcPrefix {
199
+ regions .Insert (strings .Join (splitZone [0 :3 ], "-" ))
200
+ } else {
201
+ return "" , fmt .Errorf ("zone in unexpected format, expected: {locale}-{region}-{zone} or u-{locale}-{region}-{zone}, got: %v" , zone )
196
202
}
197
- regions .Insert (strings .Join (splitZone [0 :2 ], "-" ))
198
203
}
199
204
if regions .Len () != 1 {
200
205
return "" , fmt .Errorf ("multiple or no regions gotten from zones, got: %v" , regions )
0 commit comments