Skip to content

Commit

Permalink
Add configurable timeouts to subnetworks (#871)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnraz authored and rosbo committed Dec 18, 2017
1 parent 78db4bf commit e3bd6b9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
15 changes: 11 additions & 4 deletions google/resource_compute_subnetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/hashicorp/terraform/helper/schema"
computeBeta "google.golang.org/api/compute/v0.beta"
"google.golang.org/api/compute/v1"
"time"
)

var (
Expand All @@ -28,6 +29,12 @@ func resourceComputeSubnetwork() *schema.Resource {
State: resourceComputeSubnetworkImportState,
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(6 * time.Minute),
Update: schema.DefaultTimeout(6 * time.Minute),
Delete: schema.DefaultTimeout(6 * time.Minute),
},

Schema: map[string]*schema.Schema{
"ip_cidr_range": &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -152,7 +159,7 @@ func resourceComputeSubnetworkCreate(d *schema.ResourceData, meta interface{}) e
subnetwork.Region = region
d.SetId(createSubnetID(subnetwork))

err = computeSharedOperationWait(config.clientCompute, op, project, "Creating Subnetwork")
err = computeSharedOperationWaitTime(config.clientCompute, op, project, int(d.Timeout(schema.TimeoutCreate).Minutes()), "Creating Subnetwork")
if err != nil {
return err
}
Expand Down Expand Up @@ -264,7 +271,7 @@ func resourceComputeSubnetworkUpdate(d *schema.ResourceData, meta interface{}) e
return fmt.Errorf("Error updating subnetwork PrivateIpGoogleAccess: %s", err)
}

err = computeSharedOperationWait(config.clientCompute, op, project, "Updating Subnetwork PrivateIpGoogleAccess")
err = computeSharedOperationWaitTime(config.clientCompute, op, project, int(d.Timeout(schema.TimeoutUpdate).Minutes()), "Updating Subnetwork PrivateIpGoogleAccess")
if err != nil {
return err
}
Expand All @@ -284,7 +291,7 @@ func resourceComputeSubnetworkUpdate(d *schema.ResourceData, meta interface{}) e
return fmt.Errorf("Error updating subnetwork SecondaryIpRanges: %s", err)
}

err = computeSharedOperationWait(config.clientCompute, op, project, "Updating Subnetwork SecondaryIpRanges")
err = computeSharedOperationWaitTime(config.clientCompute, op, project, int(d.Timeout(schema.TimeoutUpdate).Minutes()), "Updating Subnetwork SecondaryIpRanges")
if err != nil {
return err
}
Expand Down Expand Up @@ -317,7 +324,7 @@ func resourceComputeSubnetworkDelete(d *schema.ResourceData, meta interface{}) e
return fmt.Errorf("Error deleting subnetwork: %s", err)
}

err = computeSharedOperationWait(config.clientCompute, op, project, "Deleting Subnetwork")
err = computeSharedOperationWaitTime(config.clientCompute, op, project, int(d.Timeout(schema.TimeoutDelete).Minutes()), "Deleting Subnetwork")
if err != nil {
return err
}
Expand Down
9 changes: 9 additions & 0 deletions website/docs/r/compute_subnetwork.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ exported:

* `self_link` - The URI of the created resource.

## Timeouts

This resource provides the following
[Timeouts](/docs/configuration/resources.html#timeouts) configuration options:

- `create` - Default is `6 minutes`
- `update` - Default is `6 minutes`
- `delete` - Default is `6 minutes`

## Import

Subnetwork can be imported using the `region` and `name`, e.g.
Expand Down

0 comments on commit e3bd6b9

Please sign in to comment.