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

Add configurable timeouts to aws_route #3639

Merged
merged 1 commit into from
Mar 6, 2018
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
13 changes: 9 additions & 4 deletions aws/resource_aws_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ func resourceAwsRoute() *schema.Resource {
Delete: resourceAwsRouteDelete,
Exists: resourceAwsRouteExists,

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

Schema: map[string]*schema.Schema{
"destination_cidr_block": {
Type: schema.TypeString,
Expand Down Expand Up @@ -207,7 +212,7 @@ func resourceAwsRouteCreate(d *schema.ResourceData, meta interface{}) error {
// Create the route
var err error

err = resource.Retry(2*time.Minute, func() *resource.RetryError {
err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
_, err = conn.CreateRoute(createOpts)

if err != nil {
Expand All @@ -232,7 +237,7 @@ func resourceAwsRouteCreate(d *schema.ResourceData, meta interface{}) error {
var route *ec2.Route

if v, ok := d.GetOk("destination_cidr_block"); ok {
err = resource.Retry(2*time.Minute, func() *resource.RetryError {
err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
route, err = findResourceRoute(conn, d.Get("route_table_id").(string), v.(string), "")
return resource.RetryableError(err)
})
Expand All @@ -242,7 +247,7 @@ func resourceAwsRouteCreate(d *schema.ResourceData, meta interface{}) error {
}

if v, ok := d.GetOk("destination_ipv6_cidr_block"); ok {
err = resource.Retry(2*time.Minute, func() *resource.RetryError {
err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
route, err = findResourceRoute(conn, d.Get("route_table_id").(string), "", v.(string))
return resource.RetryableError(err)
})
Expand Down Expand Up @@ -394,7 +399,7 @@ func resourceAwsRouteDelete(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] Route delete opts: %s", deleteOpts)

var err error
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
err = resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError {
log.Printf("[DEBUG] Trying to delete route with opts %s", deleteOpts)
resp, err := conn.DeleteRoute(deleteOpts)
log.Printf("[DEBUG] Route delete result: %s", resp)
Expand Down
8 changes: 8 additions & 0 deletions website/docs/r/route.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,11 @@ will be exported as an attribute once the resource is created.
* `nat_gateway_id` - An ID of a VPC NAT gateway.
* `instance_id` - An ID of a NAT instance.
* `network_interface_id` - An ID of a network interface.

## Timeouts

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

- `create` - (Default `2 minutes`) Used for route creation
- `delete` - (Default `5 minutes`) Used for route deletion