From 3e4b66884beb9d076e6e17e1eeba822361c91c1a Mon Sep 17 00:00:00 2001 From: Julien Phalip Date: Mon, 5 Mar 2018 13:32:14 -0800 Subject: [PATCH] Let the compute zones data source accept a `project` parameter (#1122) --- google/data_source_google_compute_zones.go | 16 ++++++++++++++-- .../docs/d/google_compute_zones.html.markdown | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/google/data_source_google_compute_zones.go b/google/data_source_google_compute_zones.go index 5a71f60c..a6a48273 100644 --- a/google/data_source_google_compute_zones.go +++ b/google/data_source_google_compute_zones.go @@ -19,6 +19,11 @@ func dataSourceGoogleComputeZones() *schema.Resource { Type: schema.TypeString, Optional: true, }, + "project": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + }, "names": { Type: schema.TypeList, Computed: true, @@ -41,15 +46,20 @@ func dataSourceGoogleComputeZonesRead(d *schema.ResourceData, meta interface{}) region = r.(string) } + project, err := getProject(d, config) + if err != nil { + return err + } + regionUrl := fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/regions/%s", - config.Project, region) + project, region) filter := fmt.Sprintf("(region eq %s)", regionUrl) if s, ok := d.GetOk("status"); ok { filter += fmt.Sprintf(" (status eq %s)", s) } - call := config.clientCompute.Zones.List(config.Project).Filter(filter) + call := config.clientCompute.Zones.List(project).Filter(filter) resp, err := call.Do() if err != nil { @@ -60,6 +70,8 @@ func dataSourceGoogleComputeZonesRead(d *schema.ResourceData, meta interface{}) log.Printf("[DEBUG] Received Google Compute Zones: %q", zones) d.Set("names", zones) + d.Set("region", region) + d.Set("project", project) d.SetId(time.Now().UTC().String()) return nil diff --git a/website/docs/d/google_compute_zones.html.markdown b/website/docs/d/google_compute_zones.html.markdown index ec441f09..df1c1396 100644 --- a/website/docs/d/google_compute_zones.html.markdown +++ b/website/docs/d/google_compute_zones.html.markdown @@ -29,6 +29,7 @@ resource "google_compute_instance_group_manager" "foo" { The following arguments are supported: +* `project` (Optional) - Project from which to list available zones. Defaults to project declared in the provider. * `region` (Optional) - Region from which to list available zones. Defaults to region declared in the provider. * `status` (Optional) - Allows to filter list of zones based on their current status. Status can be either `UP` or `DOWN`. Defaults to no filtering (all available zones - both `UP` and `DOWN`).