From ddf601dbc1b80af5264d19a0b90d07998b293fcc Mon Sep 17 00:00:00 2001 From: brianbianco Date: Wed, 24 Aug 2016 09:02:06 -0400 Subject: [PATCH] provider/aws Fix import errors when aws_route has VPC endpoint Fixes #8225 If an imported aws_route contains a PrefixListId entry the RouteHashID function no longer throws a nil pointer reference. --- builtin/providers/aws/import_aws_route_table.go | 3 ++- builtin/providers/aws/resource_aws_route.go | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/builtin/providers/aws/import_aws_route_table.go b/builtin/providers/aws/import_aws_route_table.go index a226f7578eb5..98ede1b29487 100644 --- a/builtin/providers/aws/import_aws_route_table.go +++ b/builtin/providers/aws/import_aws_route_table.go @@ -43,9 +43,10 @@ func resourceAwsRouteTableImportState( // Minimal data for route d := subResource.Data(nil) d.SetType("aws_route") - d.Set("route_table_id", id) d.Set("destination_cidr_block", route.DestinationCidrBlock) + d.Set("destination_prefix_list_id", route.DestinationPrefixListId) d.SetId(routeIDHash(d, route)) + d.Set("route_table_id", id) results = append(results, d) } } diff --git a/builtin/providers/aws/resource_aws_route.go b/builtin/providers/aws/resource_aws_route.go index 9f090fad6106..baf6af3631ac 100644 --- a/builtin/providers/aws/resource_aws_route.go +++ b/builtin/providers/aws/resource_aws_route.go @@ -359,7 +359,11 @@ func resourceAwsRouteExists(d *schema.ResourceData, meta interface{}) (bool, err // Create an ID for a route func routeIDHash(d *schema.ResourceData, r *ec2.Route) string { - return fmt.Sprintf("r-%s%d", d.Get("route_table_id").(string), hashcode.String(*r.DestinationCidrBlock)) + dest := r.DestinationCidrBlock + if dest == nil { + dest = r.DestinationPrefixListId + } + return fmt.Sprintf("r-%s%d", d.Get("route_table_id").(string), hashcode.String(*dest)) } // Helper: retrieve a route