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

r/route_table: Use configurable timeouts in aws_route #21161

Merged
merged 4 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions aws/internal/service/ec2/waiter/waiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,12 @@ const (
NetworkAclEntryPropagationTimeout = 5 * time.Minute
)

func RouteDeleted(conn *ec2.EC2, routeFinder finder.RouteFinder, routeTableID, destination string) (*ec2.Route, error) {
func RouteDeleted(conn *ec2.EC2, routeFinder finder.RouteFinder, routeTableID, destination string, timeout time.Duration) (*ec2.Route, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{RouteStatusReady},
Target: []string{},
Refresh: RouteStatus(conn, routeFinder, routeTableID, destination),
Timeout: PropagationTimeout,
Timeout: timeout,
ContinuousTargetOccurence: 2,
}

Expand All @@ -282,12 +282,12 @@ func RouteDeleted(conn *ec2.EC2, routeFinder finder.RouteFinder, routeTableID, d
return nil, err
}

func RouteReady(conn *ec2.EC2, routeFinder finder.RouteFinder, routeTableID, destination string) (*ec2.Route, error) {
func RouteReady(conn *ec2.EC2, routeFinder finder.RouteFinder, routeTableID, destination string, timeout time.Duration) (*ec2.Route, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{},
Target: []string{RouteStatusReady},
Refresh: RouteStatus(conn, routeFinder, routeTableID, destination),
Timeout: PropagationTimeout,
Timeout: timeout,
ContinuousTargetOccurence: 2,
}

Expand Down
7 changes: 6 additions & 1 deletion aws/resource_aws_default_route_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"strings"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
Expand All @@ -27,6 +28,10 @@ func resourceAwsDefaultRouteTable() *schema.Resource {
State: resourceAwsDefaultRouteTableImport,
},

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

//
// The top-level attributes must be a superset of the aws_route_table resource's attributes as common CRUD handlers are used.
//
Expand Down Expand Up @@ -211,7 +216,7 @@ func resourceAwsDefaultRouteTableCreate(d *schema.ResourceData, meta interface{}
return fmt.Errorf("error deleting Route in EC2 Default Route Table (%s) with destination (%s): %w", d.Id(), destination, err)
}

_, err = waiter.RouteDeleted(conn, routeFinder, routeTableID, destination)
_, err = waiter.RouteDeleted(conn, routeFinder, routeTableID, destination, d.Timeout(schema.TimeoutCreate))

if err != nil {
return fmt.Errorf("error waiting for Route in EC2 Default Route Table (%s) with destination (%s) to delete: %w", d.Id(), destination, err)
Expand Down
7 changes: 4 additions & 3 deletions aws/resource_aws_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func resourceAwsRoute() *schema.Resource {

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

Expand Down Expand Up @@ -244,7 +245,7 @@ func resourceAwsRouteCreate(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("error creating Route in Route Table (%s) with destination (%s): %w", routeTableID, destination, err)
}

_, err = waiter.RouteReady(conn, routeFinder, routeTableID, destination)
_, err = waiter.RouteReady(conn, routeFinder, routeTableID, destination, d.Timeout(schema.TimeoutCreate))

if err != nil {
return fmt.Errorf("error waiting for Route in Route Table (%s) with destination (%s) to become available: %w", routeTableID, destination, err)
Expand Down Expand Up @@ -385,7 +386,7 @@ func resourceAwsRouteUpdate(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("error updating Route in Route Table (%s) with destination (%s): %w", routeTableID, destination, err)
}

_, err = waiter.RouteReady(conn, routeFinder, routeTableID, destination)
_, err = waiter.RouteReady(conn, routeFinder, routeTableID, destination, d.Timeout(schema.TimeoutUpdate))

if err != nil {
return fmt.Errorf("error waiting for Route in Route Table (%s) with destination (%s) to become available: %w", routeTableID, destination, err)
Expand Down Expand Up @@ -460,7 +461,7 @@ func resourceAwsRouteDelete(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("error deleting Route in Route Table (%s) with destination (%s): %w", routeTableID, destination, err)
}

_, err = waiter.RouteDeleted(conn, routeFinder, routeTableID, destination)
_, err = waiter.RouteDeleted(conn, routeFinder, routeTableID, destination, d.Timeout(schema.TimeoutDelete))

if err != nil {
return fmt.Errorf("error waiting for Route in Route Table (%s) with destination (%s) to delete: %w", routeTableID, destination, err)
Expand Down
7 changes: 3 additions & 4 deletions aws/resource_aws_route_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func resourceAwsRouteTable() *schema.Resource {
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Expand Down Expand Up @@ -514,7 +513,7 @@ func ec2RouteTableAddRoute(conn *ec2.EC2, routeTableID string, tfMap map[string]
return fmt.Errorf("error creating Route in Route Table (%s) with destination (%s): %w", routeTableID, destination, err)
}

_, err = waiter.RouteReady(conn, routeFinder, routeTableID, destination)
_, err = waiter.RouteReady(conn, routeFinder, routeTableID, destination, waiter.PropagationTimeout)

if err != nil {
return fmt.Errorf("error waiting for Route in Route Table (%s) with destination (%s) to become available: %w", routeTableID, destination, err)
Expand Down Expand Up @@ -558,7 +557,7 @@ func ec2RouteTableDeleteRoute(conn *ec2.EC2, routeTableID string, tfMap map[stri
return fmt.Errorf("error deleting Route in Route Table (%s) with destination (%s): %w", routeTableID, destination, err)
}

_, err = waiter.RouteDeleted(conn, routeFinder, routeTableID, destination)
_, err = waiter.RouteDeleted(conn, routeFinder, routeTableID, destination, waiter.PropagationTimeout)

if err != nil {
return fmt.Errorf("error waiting for Route in Route Table (%s) with destination (%s) to delete: %w", routeTableID, destination, err)
Expand Down Expand Up @@ -606,7 +605,7 @@ func ec2RouteTableUpdateRoute(conn *ec2.EC2, routeTableID string, tfMap map[stri
return fmt.Errorf("error updating Route in Route Table (%s) with destination (%s): %w", routeTableID, destination, err)
}

_, err = waiter.RouteReady(conn, routeFinder, routeTableID, destination)
_, err = waiter.RouteReady(conn, routeFinder, routeTableID, destination, waiter.PropagationTimeout)

if err != nil {
return fmt.Errorf("error waiting for Route in Route Table (%s) with destination (%s) to become available: %w", routeTableID, destination, err)
Expand Down
6 changes: 6 additions & 0 deletions website/docs/r/default_route_table.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ In addition to all arguments above, the following attributes are exported:
* `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](/docs/providers/aws/index.html#default_tags-configuration-block).
* `vpc_id` - ID of the VPC.

## Timeouts

`aws_default_route_table` provides the following [Timeouts](https://www.terraform.io/docs/configuration/blocks/resources/syntax.html#operation-timeouts) configuration options:

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

## Import

Default VPC route tables can be imported using the `vpc_id`, e.g.
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/route.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ In addition to all arguments above, the following attributes are exported:
`aws_route` provides the following [Timeouts](https://www.terraform.io/docs/configuration/blocks/resources/syntax.html#operation-timeouts) configuration options:

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

## Import
Expand Down