mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-04 17:51:11 +00:00
Let the compute zones data source accept a project
parameter (#1122)
This commit is contained in:
parent
2ea69b80b1
commit
3e4b66884b
@ -19,6 +19,11 @@ func dataSourceGoogleComputeZones() *schema.Resource {
|
|||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
},
|
},
|
||||||
|
"project": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
"names": {
|
"names": {
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeList,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
@ -41,15 +46,20 @@ func dataSourceGoogleComputeZonesRead(d *schema.ResourceData, meta interface{})
|
|||||||
region = r.(string)
|
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",
|
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)
|
filter := fmt.Sprintf("(region eq %s)", regionUrl)
|
||||||
|
|
||||||
if s, ok := d.GetOk("status"); ok {
|
if s, ok := d.GetOk("status"); ok {
|
||||||
filter += fmt.Sprintf(" (status eq %s)", s)
|
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()
|
resp, err := call.Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -60,6 +70,8 @@ func dataSourceGoogleComputeZonesRead(d *schema.ResourceData, meta interface{})
|
|||||||
log.Printf("[DEBUG] Received Google Compute Zones: %q", zones)
|
log.Printf("[DEBUG] Received Google Compute Zones: %q", zones)
|
||||||
|
|
||||||
d.Set("names", zones)
|
d.Set("names", zones)
|
||||||
|
d.Set("region", region)
|
||||||
|
d.Set("project", project)
|
||||||
d.SetId(time.Now().UTC().String())
|
d.SetId(time.Now().UTC().String())
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -29,6 +29,7 @@ resource "google_compute_instance_group_manager" "foo" {
|
|||||||
|
|
||||||
The following arguments are supported:
|
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.
|
* `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`.
|
* `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`).
|
Defaults to no filtering (all available zones - both `UP` and `DOWN`).
|
||||||
|
Loading…
Reference in New Issue
Block a user