diff --git a/CHANGELOG.md b/CHANGELOG.md index 1457e9fdb..cb9401f93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -118,6 +118,8 @@ BUG FIXES: * provider/aws: Block devices can be encrypted [GH-1718] * provider/aws: ASG health check grace period can be updated in-place [GH-1682] * provider/aws: ELB security groups can be updated in-place [GH-1662] + * provider/aws: `aws_main_route_table_association` can be deleted + manually [GH-1806] * provider/openstack: region config is not required [GH-1441] * provider/openstack: `enable_dhcp` for networking subnet should be bool [GH-1741] * provisioner/remote-exec: add random number to uploaded script path so diff --git a/builtin/providers/aws/resource_aws_main_route_table_association.go b/builtin/providers/aws/resource_aws_main_route_table_association.go index 5bae0a017..097dc1888 100644 --- a/builtin/providers/aws/resource_aws_main_route_table_association.go +++ b/builtin/providers/aws/resource_aws_main_route_table_association.go @@ -76,7 +76,7 @@ func resourceAwsMainRouteTableAssociationRead(d *schema.ResourceData, meta inter return err } - if *mainAssociation.RouteTableAssociationID != d.Id() { + if mainAssociation == nil || *mainAssociation.RouteTableAssociationID != d.Id() { // It seems it doesn't exist anymore, so clear the ID d.SetId("") } @@ -135,6 +135,9 @@ func findMainRouteTableAssociation(conn *ec2.EC2, vpcId string) (*ec2.RouteTable if err != nil { return nil, err } + if mainRouteTable == nil { + return nil, nil + } for _, a := range mainRouteTable.Associations { if *a.Main { @@ -159,10 +162,7 @@ func findMainRouteTable(conn *ec2.EC2, vpcId string) (*ec2.RouteTable, error) { if err != nil { return nil, err } else if len(routeResp.RouteTables) != 1 { - return nil, fmt.Errorf( - "Expected to find a single main routing table for VPC: %s, but found %d", - vpcId, - len(routeResp.RouteTables)) + return nil, nil } return routeResp.RouteTables[0], nil