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

fix timeout issues aws_route_table_association #30755

Merged
merged 5 commits into from
Apr 18, 2023
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
7 changes: 7 additions & 0 deletions .changelog/30755.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_route_table_association: Add configurable timeouts
```

```release-note:enhancement
resource/aws_main_route_table_association: Add configurable timeouts
```
13 changes: 10 additions & 3 deletions internal/service/ec2/vpc_main_route_table_association.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ec2
import (
"context"
"log"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
Expand All @@ -21,6 +22,12 @@ func ResourceMainRouteTableAssociation() *schema.Resource {
UpdateWithoutTimeout: resourceMainRouteTableAssociationUpdate,
DeleteWithoutTimeout: resourceMainRouteTableAssociationDelete,

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

Schema: map[string]*schema.Schema{
// We use this field to record the main route table that is automatically
// created when the VPC is created. We need this to be able to "destroy"
Expand Down Expand Up @@ -72,7 +79,7 @@ func resourceMainRouteTableAssociationCreate(ctx context.Context, d *schema.Reso
d.SetId(aws.StringValue(output.NewAssociationId))

log.Printf("[DEBUG] Waiting for Main Route Table Association (%s) creation", d.Id())
if _, err := WaitRouteTableAssociationUpdated(ctx, conn, d.Id()); err != nil {
if _, err := WaitRouteTableAssociationUpdated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for Main Route Table Association (%s) create: %s", d.Id(), err)
}

Expand Down Expand Up @@ -122,7 +129,7 @@ func resourceMainRouteTableAssociationUpdate(ctx context.Context, d *schema.Reso
d.SetId(aws.StringValue(output.NewAssociationId))

log.Printf("[DEBUG] Waiting for Main Route Table Association (%s) update", d.Id())
if _, err := WaitRouteTableAssociationUpdated(ctx, conn, d.Id()); err != nil {
if _, err := WaitRouteTableAssociationUpdated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for Main Route Table Association (%s) update: %s", d.Id(), err)
}

Expand All @@ -146,7 +153,7 @@ func resourceMainRouteTableAssociationDelete(ctx context.Context, d *schema.Reso
}

log.Printf("[DEBUG] Waiting for Main Route Table Association (%s) deletion", d.Id())
if _, err := WaitRouteTableAssociationUpdated(ctx, conn, aws.StringValue(output.NewAssociationId)); err != nil {
if _, err := WaitRouteTableAssociationUpdated(ctx, conn, aws.StringValue(output.NewAssociationId), d.Timeout(schema.TimeoutDelete)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for Main Route Table Association (%s) delete: %s", d.Id(), err)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/service/ec2/vpc_route_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ func resourceRouteTableDelete(ctx context.Context, d *schema.ResourceData, meta
for _, v := range routeTable.Associations {
v := aws.StringValue(v.RouteTableAssociationId)

if err := routeTableAssociationDelete(ctx, conn, v); err != nil {
if err := routeTableAssociationDelete(ctx, conn, v, d.Timeout(schema.TimeoutDelete)); err != nil {
return sdkdiag.AppendErrorf(diags, "deleting Route Table (%s): %s", d.Id(), err)
}
}
Expand Down
17 changes: 12 additions & 5 deletions internal/service/ec2/vpc_route_table_association.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,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,12 @@ func ResourceRouteTableAssociation() *schema.Resource {
StateContext: resourceRouteTableAssociationImport,
},

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

Schema: map[string]*schema.Schema{
"gateway_id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -80,7 +87,7 @@ func resourceRouteTableAssociationCreate(ctx context.Context, d *schema.Resource
d.SetId(aws.StringValue(output.(*ec2.AssociateRouteTableOutput).AssociationId))

log.Printf("[DEBUG] Waiting for Route Table Association (%s) creation", d.Id())
if _, err := WaitRouteTableAssociationCreated(ctx, conn, d.Id()); err != nil {
if _, err := WaitRouteTableAssociationCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for Route Table Association (%s) create: %s", d.Id(), err)
}

Expand Down Expand Up @@ -144,7 +151,7 @@ func resourceRouteTableAssociationUpdate(ctx context.Context, d *schema.Resource
d.SetId(aws.StringValue(output.NewAssociationId))

log.Printf("[DEBUG] Waiting for Route Table Association (%s) update", d.Id())
if _, err := WaitRouteTableAssociationUpdated(ctx, conn, d.Id()); err != nil {
if _, err := WaitRouteTableAssociationUpdated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for Route Table Association (%s) update: %s", d.Id(), err)
}

Expand All @@ -155,7 +162,7 @@ func resourceRouteTableAssociationDelete(ctx context.Context, d *schema.Resource
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).EC2Conn()

if err := routeTableAssociationDelete(ctx, conn, d.Id()); err != nil {
if err := routeTableAssociationDelete(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil {
return sdkdiag.AppendFromErr(diags, err)
}
return diags
Expand Down Expand Up @@ -209,7 +216,7 @@ func resourceRouteTableAssociationImport(ctx context.Context, d *schema.Resource
}

// routeTableAssociationDelete attempts to delete a route table association.
func routeTableAssociationDelete(ctx context.Context, conn *ec2.EC2, associationID string) error {
func routeTableAssociationDelete(ctx context.Context, conn *ec2.EC2, associationID string, timeout time.Duration) error {
log.Printf("[INFO] Deleting Route Table Association: %s", associationID)
_, err := conn.DisassociateRouteTableWithContext(ctx, &ec2.DisassociateRouteTableInput{
AssociationId: aws.String(associationID),
Expand All @@ -224,7 +231,7 @@ func routeTableAssociationDelete(ctx context.Context, conn *ec2.EC2, association
}

log.Printf("[DEBUG] Waiting for Route Table Association (%s) deletion", associationID)
if _, err := WaitRouteTableAssociationDeleted(ctx, conn, associationID); err != nil {
if _, err := WaitRouteTableAssociationDeleted(ctx, conn, associationID, timeout); err != nil {
return fmt.Errorf("deleting Route Table Association (%s): waiting for completion: %w", associationID, err)
}

Expand Down
12 changes: 6 additions & 6 deletions internal/service/ec2/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,12 +733,12 @@ func WaitRouteTableDeleted(ctx context.Context, conn *ec2.EC2, id string, timeou
return nil, err
}

func WaitRouteTableAssociationCreated(ctx context.Context, conn *ec2.EC2, id string) (*ec2.RouteTableAssociationState, error) {
func WaitRouteTableAssociationCreated(ctx context.Context, conn *ec2.EC2, id string, timeout time.Duration) (*ec2.RouteTableAssociationState, error) {
stateConf := &retry.StateChangeConf{
Pending: []string{ec2.RouteTableAssociationStateCodeAssociating},
Target: []string{ec2.RouteTableAssociationStateCodeAssociated},
Refresh: StatusRouteTableAssociationState(ctx, conn, id),
Timeout: RouteTableAssociationCreatedTimeout,
Timeout: timeout,
NotFoundChecks: RouteTableAssociationCreatedNotFoundChecks,
}

Expand All @@ -755,12 +755,12 @@ func WaitRouteTableAssociationCreated(ctx context.Context, conn *ec2.EC2, id str
return nil, err
}

func WaitRouteTableAssociationDeleted(ctx context.Context, conn *ec2.EC2, id string) (*ec2.RouteTableAssociationState, error) {
func WaitRouteTableAssociationDeleted(ctx context.Context, conn *ec2.EC2, id string, timeout time.Duration) (*ec2.RouteTableAssociationState, error) {
stateConf := &retry.StateChangeConf{
Pending: []string{ec2.RouteTableAssociationStateCodeDisassociating, ec2.RouteTableAssociationStateCodeAssociated},
Target: []string{},
Refresh: StatusRouteTableAssociationState(ctx, conn, id),
Timeout: RouteTableAssociationDeletedTimeout,
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForStateContext(ctx)
Expand All @@ -776,12 +776,12 @@ func WaitRouteTableAssociationDeleted(ctx context.Context, conn *ec2.EC2, id str
return nil, err
}

func WaitRouteTableAssociationUpdated(ctx context.Context, conn *ec2.EC2, id string) (*ec2.RouteTableAssociationState, error) {
func WaitRouteTableAssociationUpdated(ctx context.Context, conn *ec2.EC2, id string, timeout time.Duration) (*ec2.RouteTableAssociationState, error) {
stateConf := &retry.StateChangeConf{
Pending: []string{ec2.RouteTableAssociationStateCodeAssociating},
Target: []string{ec2.RouteTableAssociationStateCodeAssociated},
Refresh: StatusRouteTableAssociationState(ctx, conn, id),
Timeout: RouteTableAssociationUpdatedTimeout,
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForStateContext(ctx)
Expand Down
8 changes: 8 additions & 0 deletions website/docs/r/main_route_table_association.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,11 @@ the `main_route_table_association` delete to work properly.
[aws-route-tables]: http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Route_Tables.html#Route_Replacing_Main_Table
[tf-route-tables]: /docs/providers/aws/r/route_table.html
[tf-default-route-table]: /docs/providers/aws/r/default_route_table.html

## Timeouts

[Configuration options](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts):

- `create` - (Default `5m`)
- `update` - (Default `2m`)
- `delete` - (Default `5m`)
8 changes: 8 additions & 0 deletions website/docs/r/route_table_association.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ In addition to all arguments above, the following attributes are exported:

* `id` - The ID of the association

## Timeouts

[Configuration options](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts):

- `create` - (Default `5m`)
- `update` - (Default `2m`)
- `delete` - (Default `5m`)

## Import

~> **NOTE:** Attempting to associate a route table with a subnet or gateway, where either
Expand Down