mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
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:
commit
abb51e02bb
@ -150,7 +150,7 @@ func resourceAwsRouteCreate(d *schema.ResourceData, meta interface{}) error {
|
|||||||
VpcPeeringConnectionId: aws.String(d.Get("vpc_peering_connection_id").(string)),
|
VpcPeeringConnectionId: aws.String(d.Get("vpc_peering_connection_id").(string)),
|
||||||
}
|
}
|
||||||
default:
|
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)
|
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 {
|
func resourceAwsRouteRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
conn := meta.(*AWSClient).ec2conn
|
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 err != nil {
|
||||||
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidRouteTableID.NotFound" {
|
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("")
|
d.SetId("")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -289,7 +292,7 @@ func resourceAwsRouteUpdate(d *schema.ResourceData, meta interface{}) error {
|
|||||||
VpcPeeringConnectionId: aws.String(d.Get("vpc_peering_connection_id").(string)),
|
VpcPeeringConnectionId: aws.String(d.Get("vpc_peering_connection_id").(string)),
|
||||||
}
|
}
|
||||||
default:
|
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)
|
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)
|
res, err := conn.DescribeRouteTables(findOpts)
|
||||||
if err != nil {
|
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)
|
return false, fmt.Errorf("Error while checking if route exists: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(res.RouteTables) < 1 || res.RouteTables[0] == nil {
|
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)
|
routeTableId)
|
||||||
return false, nil
|
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 {
|
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)
|
routeTableID)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -400,7 +407,6 @@ func findResourceRoute(conn *ec2.EC2, rtbid string, cidr string) (*ec2.Route, er
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf(
|
return nil, fmt.Errorf("Unable to find matching route for Route Table (%s) "+
|
||||||
`error finding matching route for Route table (%s) and destination CIDR block (%s)`,
|
"and destination CIDR block (%s).", rtbid, cidr)
|
||||||
rtbid, cidr)
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user