Skip to content

Commit

Permalink
Fix inconsistent read after create for vpc_route_table
Browse files Browse the repository at this point in the history
  • Loading branch information
alenkacz committed Apr 26, 2023
1 parent 473d798 commit 6e6f908
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions internal/service/ec2/vpc_route_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,9 @@ func resourceRouteTableCreate(ctx context.Context, d *schema.ResourceData, meta
func resourceRouteTableRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).EC2Conn()

routeTable, err := FindRouteTableByID(ctx, conn, d.Id())
outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, RouteTableAssociationPropagationTimeout, func() (interface{}, error) {
return FindRouteTableByID(ctx, conn, d.Id())
}, d.IsNewResource())

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] Route Table (%s) not found, removing from state", d.Id())
Expand All @@ -225,6 +226,7 @@ func resourceRouteTableRead(ctx context.Context, d *schema.ResourceData, meta in
return sdkdiag.AppendErrorf(diags, "reading Route Table (%s): %s", d.Id(), err)
}

routeTable := outputRaw.(*ec2.RouteTable)
ownerID := aws.StringValue(routeTable.OwnerId)
arn := arn.ARN{
Partition: meta.(*conns.AWSClient).Partition,
Expand Down Expand Up @@ -349,7 +351,6 @@ func resourceRouteTableDelete(ctx context.Context, d *schema.ResourceData, meta
conn := meta.(*conns.AWSClient).EC2Conn()

routeTable, err := FindRouteTableByID(ctx, conn, d.Id())

if err != nil {
return sdkdiag.AppendErrorf(diags, "reading Route Table (%s): %s", d.Id(), err)
}
Expand Down Expand Up @@ -492,7 +493,6 @@ func routeTableAddRoute(ctx context.Context, conn *ec2.EC2, routeTableID string,
errCodeInvalidParameterException,
errCodeInvalidTransitGatewayIDNotFound,
)

if err != nil {
return fmt.Errorf("creating Route in Route Table (%s) with destination (%s): %w", routeTableID, destination, err)
}
Expand Down Expand Up @@ -578,7 +578,6 @@ func routeTableUpdateRoute(ctx context.Context, conn *ec2.EC2, routeTableID stri
input.RouteTableId = aws.String(routeTableID)

_, err := conn.ReplaceRouteWithContext(ctx, input)

if err != nil {
return fmt.Errorf("updating Route in Route Table (%s) with destination (%s): %w", routeTableID, destination, err)
}
Expand All @@ -599,7 +598,6 @@ func routeTableDisableVGWRoutePropagation(ctx context.Context, conn *ec2.EC2, ro
}

_, err := conn.DisableVgwRoutePropagationWithContext(ctx, input)

if err != nil {
return fmt.Errorf("disabling Route Table (%s) VPN Gateway (%s) route propagation: %w", routeTableID, gatewayID, err)
}
Expand All @@ -622,7 +620,6 @@ func routeTableEnableVGWRoutePropagation(ctx context.Context, conn *ec2.EC2, rou
},
errCodeGatewayNotAttached,
)

if err != nil {
return fmt.Errorf("enabling Route Table (%s) VPN Gateway (%s) route propagation: %w", routeTableID, gatewayID, err)
}
Expand Down

0 comments on commit 6e6f908

Please sign in to comment.