mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-06 09:06:44 +00:00
![Dana Hoffman](/assets/img/avatar_default.png)
* Add wait_for_instances field to IGM and self_link option to the IG data source * don't be clever with errors
106 lines
2.2 KiB
Go
106 lines
2.2 KiB
Go
package google
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
)
|
|
|
|
func dataSourceGoogleComputeInstanceGroup() *schema.Resource {
|
|
return &schema.Resource{
|
|
Read: dataSourceComputeInstanceGroupRead,
|
|
Schema: map[string]*schema.Schema{
|
|
"name": {
|
|
Type: schema.TypeString,
|
|
Optional: true,
|
|
ConflictsWith: []string{"self_link"},
|
|
},
|
|
|
|
"self_link": {
|
|
Type: schema.TypeString,
|
|
Optional: true,
|
|
Computed: true,
|
|
ConflictsWith: []string{"name", "zone"},
|
|
},
|
|
|
|
"zone": {
|
|
Type: schema.TypeString,
|
|
Optional: true,
|
|
Computed: true,
|
|
ConflictsWith: []string{"self_link"},
|
|
},
|
|
|
|
"project": {
|
|
Type: schema.TypeString,
|
|
Optional: true,
|
|
Computed: true,
|
|
},
|
|
|
|
"description": {
|
|
Type: schema.TypeString,
|
|
Computed: true,
|
|
},
|
|
|
|
"instances": {
|
|
Type: schema.TypeSet,
|
|
Computed: true,
|
|
Elem: &schema.Schema{Type: schema.TypeString},
|
|
Set: schema.HashString,
|
|
},
|
|
|
|
"named_port": {
|
|
Type: schema.TypeList,
|
|
Computed: true,
|
|
Elem: &schema.Resource{
|
|
Schema: map[string]*schema.Schema{
|
|
"name": {
|
|
Type: schema.TypeString,
|
|
Computed: true,
|
|
},
|
|
|
|
"port": {
|
|
Type: schema.TypeInt,
|
|
Computed: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
|
|
"network": {
|
|
Type: schema.TypeString,
|
|
Computed: true,
|
|
},
|
|
|
|
"size": {
|
|
Type: schema.TypeInt,
|
|
Computed: true,
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func dataSourceComputeInstanceGroupRead(d *schema.ResourceData, meta interface{}) error {
|
|
config := meta.(*Config)
|
|
if name, ok := d.GetOk("name"); ok {
|
|
zone, err := getZone(d, config)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
d.SetId(fmt.Sprintf("%s/%s", zone, name.(string)))
|
|
} else if selfLink, ok := d.GetOk("self_link"); ok {
|
|
parsed, err := ParseInstanceGroupFieldValue(selfLink.(string), d, config)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
d.Set("name", parsed.Name)
|
|
d.Set("zone", parsed.Zone)
|
|
d.Set("project", parsed.Project)
|
|
d.SetId(fmt.Sprintf("%s/%s", parsed.Zone, parsed.Name))
|
|
} else {
|
|
return errors.New("Must provide either `self_link` or `zone/name`")
|
|
}
|
|
|
|
return resourceComputeInstanceGroupRead(d, meta)
|
|
}
|