Merge pull request #9431 from kwilczynski/fix/handle-missing-route-aws_route

provider/aws: Handle the case where Route Table is already gone.
This commit is contained in:
James Nugent 2016-10-18 07:37:54 -05:00 committed by GitHub
commit abb51e02bb
1 changed files with 15 additions and 9 deletions

View File

@ -150,7 +150,7 @@ func resourceAwsRouteCreate(d *schema.ResourceData, meta interface{}) error {
VpcPeeringConnectionId: aws.String(d.Get("vpc_peering_connection_id").(string)),
}
default:
return fmt.Errorf("Error: invalid target type specified.")
return fmt.Errorf("An invalid target type specified: %s", setTarget)
}
log.Printf("[DEBUG] Route create config: %s", createOpts)
@ -195,10 +195,13 @@ func resourceAwsRouteCreate(d *schema.ResourceData, meta interface{}) error {
func resourceAwsRouteRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn
route, err := findResourceRoute(conn, d.Get("route_table_id").(string), d.Get("destination_cidr_block").(string))
routeTableId := d.Get("route_table_id").(string)
route, err := findResourceRoute(conn, routeTableId, d.Get("destination_cidr_block").(string))
if err != nil {
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidRouteTableID.NotFound" {
log.Printf("[WARN] AWS RouteTable not found. Removing Route from state")
log.Printf("[WARN] Route Table %q could not be found. Removing Route from state.",
routeTableId)
d.SetId("")
return nil
}
@ -289,7 +292,7 @@ func resourceAwsRouteUpdate(d *schema.ResourceData, meta interface{}) error {
VpcPeeringConnectionId: aws.String(d.Get("vpc_peering_connection_id").(string)),
}
default:
return fmt.Errorf("Error: invalid target type specified.")
return fmt.Errorf("An invalid target type specified: %s", setTarget)
}
log.Printf("[DEBUG] Route replace config: %s", replaceOpts)
@ -352,11 +355,15 @@ func resourceAwsRouteExists(d *schema.ResourceData, meta interface{}) (bool, err
res, err := conn.DescribeRouteTables(findOpts)
if err != nil {
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidRouteTableID.NotFound" {
log.Printf("[WARN] Route Table %q could not be found.", routeTableId)
return false, nil
}
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.",
log.Printf("[WARN] Route Table %q is gone, or route does not exist.",
routeTableId)
return false, nil
}
@ -390,7 +397,7 @@ func findResourceRoute(conn *ec2.EC2, rtbid string, cidr string) (*ec2.Route, er
}
if len(resp.RouteTables) < 1 || resp.RouteTables[0] == nil {
return nil, fmt.Errorf("Route table %s is gone, so route does not exist.",
return nil, fmt.Errorf("Route Table %q is gone, or route does not exist.",
routeTableID)
}
@ -400,7 +407,6 @@ func findResourceRoute(conn *ec2.EC2, rtbid string, cidr string) (*ec2.Route, er
}
}
return nil, fmt.Errorf(
`error finding matching route for Route table (%s) and destination CIDR block (%s)`,
rtbid, cidr)
return nil, fmt.Errorf("Unable to find matching route for Route Table (%s) "+
"and destination CIDR block (%s).", rtbid, cidr)
}