@@ -119,7 +119,7 @@ func (c *Client) GetMachineTypeWithZones(ctx context.Context, project, region, m
119119 return nil , nil , err
120120 }
121121
122- pz , err := GetZones (ctx , svc , project , fmt . Sprintf ( " region eq .*%s" , region ) )
122+ pz , err := GetZones (ctx , svc , project , region )
123123 if err != nil {
124124 return nil , nil , err
125125 }
@@ -379,34 +379,33 @@ func (c *Client) GetRegions(ctx context.Context, project string) ([]string, erro
379379 return computeRegions , nil
380380}
381381
382- // GetZones uses the GCP Compute Service API to get a list of zones from a project.
383- func GetZones (ctx context.Context , svc * compute.Service , project , filter string ) ([]* compute.Zone , error ) {
382+ // GetZones uses the GCP Compute Service API to get a list of zones with UP status in a region from a project.
383+ func GetZones (ctx context.Context , svc * compute.Service , project , region string ) ([]* compute.Zone , error ) {
384384 req := svc .Zones .List (project )
385- if filter != "" {
386- req = req .Filter (filter )
387- }
388-
389385 zones := []* compute.Zone {}
390386 ctx , cancel := context .WithTimeout (ctx , defaultTimeout )
391387 defer cancel ()
392388 if err := req .Pages (ctx , func (page * compute.ZoneList ) error {
393- zones = append (zones , page .Items ... )
389+ for _ , zone := range page .Items {
390+ if strings .HasSuffix (zone .Region , region ) && strings .EqualFold (zone .Status , "UP" ) {
391+ zones = append (zones , zone )
392+ }
393+ }
394394 return nil
395395 }); err != nil {
396396 return nil , errors .Wrapf (err , "failed to get zones from project %s" , project )
397397 }
398-
399398 return zones , nil
400399}
401400
402401// GetZones uses the GCP Compute Service API to get a list of zones from a project.
403- func (c * Client ) GetZones (ctx context.Context , project , filter string ) ([]* compute.Zone , error ) {
402+ func (c * Client ) GetZones (ctx context.Context , project , region string ) ([]* compute.Zone , error ) {
404403 svc , err := c .getComputeService (ctx )
405404 if err != nil {
406405 return nil , err
407406 }
408407
409- return GetZones (ctx , svc , project , filter )
408+ return GetZones (ctx , svc , project , region )
410409}
411410
412411func (c * Client ) getCloudResourceService (ctx context.Context ) (* cloudresourcemanager.Service , error ) {
0 commit comments