Let the compute zones data source accept a project parameter (#1122)

This commit is contained in:
Julien Phalip 2018-03-05 13:32:14 -08:00 committed by Vincent Roseberry
parent 2ea69b80b1
commit 3e4b66884b
2 changed files with 15 additions and 2 deletions

View File

@ -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

View File

@ -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`).