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

provider/aws: Retry finding route after creating it #7463

Merged
merged 1 commit into from
Jul 5, 2016
Merged
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
22 changes: 14 additions & 8 deletions builtin/providers/aws/resource_aws_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,18 @@ func resourceAwsRouteCreate(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("Error creating route: %s", err)
}

route, err := findResourceRoute(conn, d.Get("route_table_id").(string), d.Get("destination_cidr_block").(string))
var route *ec2.Route
err = resource.Retry(15*time.Second, func() *resource.RetryError {
route, err = findResourceRoute(conn, d.Get("route_table_id").(string), d.Get("destination_cidr_block").(string))
return resource.RetryableError(err)
})
if err != nil {
return err
return fmt.Errorf("Error finding route after creating it: %s", err)
}

d.SetId(routeIDHash(d, route))

return resourceAwsRouteRead(d, meta)
resourceAwsRouteSetResourceData(d, route)
return nil
}

func resourceAwsRouteRead(d *schema.ResourceData, meta interface{}) error {
Expand All @@ -195,7 +199,11 @@ func resourceAwsRouteRead(d *schema.ResourceData, meta interface{}) error {
if err != nil {
return err
}
resourceAwsRouteSetResourceData(d, route)
return nil
}

func resourceAwsRouteSetResourceData(d *schema.ResourceData, route *ec2.Route) {
d.Set("destination_prefix_list_id", route.DestinationPrefixListId)
d.Set("gateway_id", route.GatewayId)
d.Set("nat_gateway_id", route.NatGatewayId)
Expand All @@ -205,8 +213,6 @@ func resourceAwsRouteRead(d *schema.ResourceData, meta interface{}) error {
d.Set("origin", route.Origin)
d.Set("state", route.State)
d.Set("vpc_peering_connection_id", route.VpcPeeringConnectionId)

return nil
}

func resourceAwsRouteUpdate(d *schema.ResourceData, meta interface{}) error {
Expand Down Expand Up @@ -380,7 +386,7 @@ func findResourceRoute(conn *ec2.EC2, rtbid string, cidr string) (*ec2.Route, er
}
}

return nil, fmt.Errorf(`
error finding matching route for Route table (%s) and destination CIDR block (%s)`,
return nil, fmt.Errorf(
`error finding matching route for Route table (%s) and destination CIDR block (%s)`,
rtbid, cidr)
}