Skip to content

Commit

Permalink
resource/aws_route: SetId before WaitRouteReady
Browse files Browse the repository at this point in the history
When the route's wait-for-creation operation times out,
its state is leaked as `d.SetId(...)` is called after the
`WaitRouteReady(...)`. So, the next time the configuration
is applied, the Terraform engine tries to create the same
route again, getting duplication error from AWS.

Call `d.SetId(...)` before `WaitRouteReady(...)`.

Fixes: hashicorp#23827
  • Loading branch information
gmichelo committed Apr 4, 2022
1 parent 82b343f commit 3776f51
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/service/ec2/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,14 @@ func resourceRouteCreate(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("error creating Route in Route Table (%s) with destination (%s): %w", routeTableID, destination, err)
}

d.SetId(RouteCreateID(routeTableID, destination))

_, err = WaitRouteReady(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)
}

d.SetId(RouteCreateID(routeTableID, destination))

return resourceRouteRead(d, meta)
}

Expand Down

0 comments on commit 3776f51

Please sign in to comment.