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