@@ -180,17 +180,22 @@ func NodeIDToZoneAndName(id string) (string, string, error) {
180180}
181181
182182func GetRegionFromZones (zones []string ) (string , error ) {
183+ const tpcPrefix = "u"
183184 regions := sets.String {}
184185 if len (zones ) < 1 {
185186 return "" , fmt .Errorf ("no zones specified" )
186187 }
187188 for _ , zone := range zones {
188189 // Zone expected format {locale}-{region}-{zone}
190+ // TPC zone expected format is u-{}-{}-{}, e.g. u-europe-central2-a. See go/tpc-region-naming.
189191 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 )
192198 }
193- regions .Insert (strings .Join (splitZone [0 :2 ], "-" ))
194199 }
195200 if regions .Len () != 1 {
196201 return "" , fmt .Errorf ("multiple or no regions gotten from zones, got: %v" , regions )
0 commit comments