Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/gce: Make region optional for remaining GCE resources #3258

Merged
merged 1 commit into from
Oct 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions builtin/providers/google/resource_compute_backend_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ func resourceComputeBackendService() *schema.Resource {
Optional: true,
},

"region": &schema.Schema{
Type: schema.TypeString,
ForceNew: true,
Optional: true,
},

"health_checks": &schema.Schema{
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Expand Down
42 changes: 25 additions & 17 deletions builtin/providers/google/resource_compute_target_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ func resourceComputeTargetPool() *schema.Resource {
Optional: true,
ForceNew: true,
},

"region": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
},
}
}
Expand Down Expand Up @@ -115,6 +121,7 @@ func convertInstances(config *Config, names []string) ([]string, error) {

func resourceComputeTargetPoolCreate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
region := getOptionalRegion(d, config)

hchkUrls, err := convertHealthChecks(
config, convertStringArr(d.Get("health_checks").([]interface{})))
Expand Down Expand Up @@ -142,19 +149,18 @@ func resourceComputeTargetPoolCreate(d *schema.ResourceData, meta interface{}) e
}
log.Printf("[DEBUG] TargetPool insert request: %#v", tpool)
op, err := config.clientCompute.TargetPools.Insert(
config.Project, config.Region, tpool).Do()
config.Project, region, tpool).Do()
if err != nil {
return fmt.Errorf("Error creating TargetPool: %s", err)
}

// It probably maybe worked, so store the ID now
d.SetId(tpool.Name)

err = computeOperationWaitRegion(config, op, config.Region, "Creating Target Pool")
err = computeOperationWaitRegion(config, op, region, "Creating Target Pool")
if err != nil {
return err
}

return resourceComputeTargetPoolRead(d, meta)
}

Expand Down Expand Up @@ -190,6 +196,7 @@ func calcAddRemove(from []string, to []string) ([]string, []string) {

func resourceComputeTargetPoolUpdate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
region := getOptionalRegion(d, config)

d.Partial(true)

Expand All @@ -215,12 +222,12 @@ func resourceComputeTargetPoolUpdate(d *schema.ResourceData, meta interface{}) e
removeReq.HealthChecks[i] = &compute.HealthCheckReference{HealthCheck: v}
}
op, err := config.clientCompute.TargetPools.RemoveHealthCheck(
config.Project, config.Region, d.Id(), removeReq).Do()
config.Project, region, d.Id(), removeReq).Do()
if err != nil {
return fmt.Errorf("Error updating health_check: %s", err)
}

err = computeOperationWaitRegion(config, op, config.Region, "Updating Target Pool")
err = computeOperationWaitRegion(config, op, region, "Updating Target Pool")
if err != nil {
return err
}
Expand All @@ -231,12 +238,12 @@ func resourceComputeTargetPoolUpdate(d *schema.ResourceData, meta interface{}) e
addReq.HealthChecks[i] = &compute.HealthCheckReference{HealthCheck: v}
}
op, err = config.clientCompute.TargetPools.AddHealthCheck(
config.Project, config.Region, d.Id(), addReq).Do()
config.Project, region, d.Id(), addReq).Do()
if err != nil {
return fmt.Errorf("Error updating health_check: %s", err)
}

err = computeOperationWaitRegion(config, op, config.Region, "Updating Target Pool")
err = computeOperationWaitRegion(config, op, region, "Updating Target Pool")
if err != nil {
return err
}
Expand Down Expand Up @@ -265,12 +272,12 @@ func resourceComputeTargetPoolUpdate(d *schema.ResourceData, meta interface{}) e
addReq.Instances[i] = &compute.InstanceReference{Instance: v}
}
op, err := config.clientCompute.TargetPools.AddInstance(
config.Project, config.Region, d.Id(), addReq).Do()
config.Project, region, d.Id(), addReq).Do()
if err != nil {
return fmt.Errorf("Error updating instances: %s", err)
}

err = computeOperationWaitRegion(config, op, config.Region, "Updating Target Pool")
err = computeOperationWaitRegion(config, op, region, "Updating Target Pool")
if err != nil {
return err
}
Expand All @@ -281,12 +288,11 @@ func resourceComputeTargetPoolUpdate(d *schema.ResourceData, meta interface{}) e
removeReq.Instances[i] = &compute.InstanceReference{Instance: v}
}
op, err = config.clientCompute.TargetPools.RemoveInstance(
config.Project, config.Region, d.Id(), removeReq).Do()
config.Project, region, d.Id(), removeReq).Do()
if err != nil {
return fmt.Errorf("Error updating instances: %s", err)
}

err = computeOperationWaitRegion(config, op, config.Region, "Updating Target Pool")
err = computeOperationWaitRegion(config, op, region, "Updating Target Pool")
if err != nil {
return err
}
Expand All @@ -299,12 +305,12 @@ func resourceComputeTargetPoolUpdate(d *schema.ResourceData, meta interface{}) e
Target: bpool_name,
}
op, err := config.clientCompute.TargetPools.SetBackup(
config.Project, config.Region, d.Id(), tref).Do()
config.Project, region, d.Id(), tref).Do()
if err != nil {
return fmt.Errorf("Error updating backup_pool: %s", err)
}

err = computeOperationWaitRegion(config, op, config.Region, "Updating Target Pool")
err = computeOperationWaitRegion(config, op, region, "Updating Target Pool")
if err != nil {
return err
}
Expand All @@ -318,9 +324,10 @@ func resourceComputeTargetPoolUpdate(d *schema.ResourceData, meta interface{}) e

func resourceComputeTargetPoolRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
region := getOptionalRegion(d, config)

tpool, err := config.clientCompute.TargetPools.Get(
config.Project, config.Region, d.Id()).Do()
config.Project, region, d.Id()).Do()
if err != nil {
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
// The resource doesn't exist anymore
Expand All @@ -339,15 +346,16 @@ func resourceComputeTargetPoolRead(d *schema.ResourceData, meta interface{}) err

func resourceComputeTargetPoolDelete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
region := getOptionalRegion(d, config)

// Delete the TargetPool
op, err := config.clientCompute.TargetPools.Delete(
config.Project, config.Region, d.Id()).Do()
config.Project, region, d.Id()).Do()
if err != nil {
return fmt.Errorf("Error deleting TargetPool: %s", err)
}

err = computeOperationWaitRegion(config, op, config.Region, "Deleting Target Pool")
err = computeOperationWaitRegion(config, op, region, "Deleting Target Pool")
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ resource "google_compute_backend_service" "foobar" {
port_name = "http"
protocol = "HTTP"
timeout_sec = 10
region = us-central1

backend {
group = "${google_compute_instance_group_manager.foo.instance_group}"
Expand Down Expand Up @@ -67,6 +68,7 @@ The following arguments are supported:
for checking the health of the backend service.
* `description` - (Optional) The textual description for the backend service.
* `backend` - (Optional) The list of backends that serve this BackendService. See *Backend* below.
* `region` - (Optional) The region the service sits in. If not specified, the project region is used.
* `port_name` - (Optional) The name of a service that has been added to
an instance group in this backend. See [related docs](https://cloud.google.com/compute/docs/instance-groups/#specifying_service_endpoints)
for details. Defaults to http.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ The following arguments are supported:

* `session_affinity` - (Optional) How to distribute load. Options are "NONE" (no affinity). "CLIENT\_IP" (hash of the source/dest addresses / ports), and "CLIENT\_IP\_PROTO" also includes the protocol (default "NONE").

* `region` - (Optional) Where the target pool resides. Defaults to project region.

## Attributes Reference

Expand Down