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: fix potential aws_route crashes #5867

Merged
merged 1 commit into from
Mar 29, 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
13 changes: 12 additions & 1 deletion builtin/providers/aws/resource_aws_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,13 @@ func resourceAwsRouteExists(d *schema.ResourceData, meta interface{}) (bool, err

res, err := conn.DescribeRouteTables(findOpts)
if err != nil {
return false, err
return false, fmt.Errorf("Error while checking if route exists: %s", err)
}

if len(res.RouteTables) < 1 || res.RouteTables[0] == nil {
log.Printf("[WARN] Route table %s is gone, so route does not exist.",
routeTableId)
return false, nil
}

cidr := d.Get("destination_cidr_block").(string)
Expand Down Expand Up @@ -320,6 +326,11 @@ func findResourceRoute(conn *ec2.EC2, rtbid string, cidr string) (*ec2.Route, er
return nil, err
}

if len(resp.RouteTables) < 1 || resp.RouteTables[0] == nil {
return nil, fmt.Errorf("Route table %s is gone, so route does not exist.",
routeTableID)
}

for _, route := range (*resp.RouteTables[0]).Routes {
if *route.DestinationCidrBlock == cidr {
return route, nil
Expand Down