Repository: ansible-collections/community.aws

Issue:
ec2_vpc_route_table not idempotent - failing on adding already existing route
This issue was already reported in the old Ansible repo here https://github.com/ansible/ansible/issues/59863 but wasn't migrated over.

##### SUMMARY
when rerunning ec2_vpc_route_table module with the same route listing if fails with 
```
botocore.exceptions.ClientError: An error occurred (RouteAlreadyExists) when calling the CreateRoute operation: The route identified by 10.31.0.0/16 already exists.
```

IMO the module should catch that error and should just return `changed: false`.

##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME
ec2_vpc_route_table

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes -->
```paste below
ansible 2.9.1
  config file = ~/be-infrastructure/ansible.cfg
  configured module search path = ['~/be-infrastructure/library']
  ansible python module location = ~/.local/lib/python3.8/site-packages/ansible
  executable location = ~/.local/bin/ansible
  python version = 3.8.5 (default, Jul 28 2020, 12:59:40) [GCC 9.3.0]
```

Couldn't test with newer version yet. However I would assume that this still happens in newer version, as the ticket in the old repo was open till the end and the module hasn't seen any code changes since the migration as far I can see.
See https://github.com/ansible-collections/community.aws/commits/main/plugins/modules/ec2_vpc_route_table.py

##### ADDTIONAL INFORMATION
For other details just look up https://github.com/ansible/ansible/issues/59863



Discussion:
PR that attempts to fix this https://github.com/ansible-collections/community.aws/pull/359
cc @jillr @s-hertel @tremble @willthames @wimnat
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/plugins/modules/ec2_vpc_route_table.py b/plugins/modules/ec2_vpc_route_table.py
--- a/plugins/modules/ec2_vpc_route_table.py
+++ b/plugins/modules/ec2_vpc_route_table.py
@@ -492,20 +492,16 @@ def ensure_routes(connection=None, module=None, route_table=None, route_specs=No
 
         for route_spec in route_specs_to_recreate:
             try:
-                connection.replace_route(
-                    aws_retry=True,
-                    RouteTableId=route_table['RouteTableId'],
-                    **route_spec)
+                connection.replace_route(aws_retry=True, RouteTableId=route_table['RouteTableId'], **route_spec)
             except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
                 module.fail_json_aws(e, msg="Couldn't recreate route")
 
         for route_spec in route_specs_to_create:
             try:
-                connection.create_route(
-                    aws_retry=True,
-                    RouteTableId=route_table['RouteTableId'],
-                    **route_spec)
-            except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
+                connection.create_route(aws_retry=True, RouteTableId=route_table['RouteTableId'], **route_spec)
+            except is_boto3_error_code('RouteAlreadyExists'):
+                changed = False
+            except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:  # pylint: disable=duplicate-except
                 module.fail_json_aws(e, msg="Couldn't create route")
 
     return {'changed': bool(changed)}


Test patch: