From 70096c5ac0475d3b0150af7537b2bf26a67f6d63 Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Fri, 25 Mar 2016 14:55:27 -0500 Subject: [PATCH] provider/aws: fix potential aws_route crashes Fixes #5865 --- builtin/providers/aws/resource_aws_route.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_route.go b/builtin/providers/aws/resource_aws_route.go index 2a9aa4427a..1232067c4f 100644 --- a/builtin/providers/aws/resource_aws_route.go +++ b/builtin/providers/aws/resource_aws_route.go @@ -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) @@ -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