diff --git a/builtin/providers/aws/import_aws_route_table.go b/builtin/providers/aws/import_aws_route_table.go index a1a897fa3..c6e694773 100644 --- a/builtin/providers/aws/import_aws_route_table.go +++ b/builtin/providers/aws/import_aws_route_table.go @@ -27,24 +27,45 @@ func resourceAwsRouteTableImportState( table := resp.RouteTables[0] // Start building our results - results := make([]*schema.ResourceData, 1, 1+len(table.Routes)) + results := make([]*schema.ResourceData, 1, + 1+len(table.Associations)+len(table.Routes)) results[0] = d - // Construct the routes - subResource := resourceAwsRoute() - for _, route := range table.Routes { - // Ignore the local/default route - if route.GatewayId != nil && *route.GatewayId == "local" { - continue - } + { + // Construct the routes + subResource := resourceAwsRoute() + for _, route := range table.Routes { + // Ignore the local/default route + if route.GatewayId != nil && *route.GatewayId == "local" { + continue + } - // 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.SetId(routeIDHash(d, route)) - results = append(results, d) + // 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.SetId(routeIDHash(d, route)) + results = append(results, d) + } + } + + { + // Construct the associations + subResource := resourceAwsRouteTableAssociation() + for _, assoc := range table.Associations { + if *assoc.Main { + // Ignore + continue + } + + // Minimal data for route + d := subResource.Data(nil) + d.SetType("aws_route_table_association") + d.Set("route_table_id", assoc.RouteTableId) + d.SetId(*assoc.RouteTableAssociationId) + results = append(results, d) + } } return results, nil