mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-03 08:42:39 +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,
|
||||
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
|
||||
|
|
|
@ -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`).
|
||||
|
|
Loading…
Reference in New Issue
Block a user