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_vpc_route_read_error #32196

Merged
merged 6 commits into from
Jun 26, 2023
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
15 changes: 10 additions & 5 deletions internal/service/ec2/vpc_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,12 @@ func resourceRouteCreate(ctx context.Context, d *schema.ResourceData, meta inter
}

func resourceRouteRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {

var diags diag.Diagnostics
var routeFinder RouteFinder

routeTableID := d.Get("route_table_id").(string)

conn := meta.(*conns.AWSClient).EC2Conn(ctx)

destinationAttributeKey, destination, err := routeDestinationAttribute(d)
Expand All @@ -274,8 +279,6 @@ func resourceRouteRead(ctx context.Context, d *schema.ResourceData, meta interfa
return sdkdiag.AppendErrorf(diags, "reading Route: %s", err)
}

var routeFinder RouteFinder

switch destinationAttributeKey {
case routeDestinationCIDRBlock:
routeFinder = FindRouteByIPv4Destination
Expand All @@ -287,9 +290,9 @@ func resourceRouteRead(ctx context.Context, d *schema.ResourceData, meta interfa
return sdkdiag.AppendErrorf(diags, "reading Route: unexpected route destination attribute: %q", destinationAttributeKey)
}

routeTableID := d.Get("route_table_id").(string)

route, err := routeFinder(ctx, conn, routeTableID, destination)
outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, RoutePropagationTimeout, func() (interface{}, error) {
return routeFinder(ctx, conn, routeTableID, destination)
}, d.IsNewResource())

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] Route in Route Table (%s) with destination (%s) not found, removing from state", routeTableID, destination)
Expand All @@ -301,6 +304,8 @@ func resourceRouteRead(ctx context.Context, d *schema.ResourceData, meta interfa
return sdkdiag.AppendErrorf(diags, "reading Route in Route Table (%s) with destination (%s): %s", routeTableID, destination, err)
}

route := outputRaw.(*ec2.Route)

d.Set("carrier_gateway_id", route.CarrierGatewayId)
d.Set("core_network_arn", route.CoreNetworkArn)
d.Set(routeDestinationCIDRBlock, route.DestinationCidrBlock)
Expand Down
4 changes: 4 additions & 0 deletions internal/service/ec2/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,10 @@ func WaitRouteReady(ctx context.Context, conn *ec2.EC2, routeFinder RouteFinder,
return nil, err
}

const (
RoutePropagationTimeout = 5 & time.Minute
)

const (
RouteTableAssociationPropagationTimeout = 5 * time.Minute

Expand Down