Skip to content

Commit

Permalink
ec2_vpc_route_table: Don't fail if a route was already created. (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhorning committed Mar 24, 2021
1 parent 0412f00 commit 73d60e5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/359-fix-ec2_vpc_route_table.yml
@@ -0,0 +1,2 @@
bugfixes:
- ec2_vpc_route_table - catch RouteAlreadyExists error when rerunning same task twice to make module idempotent
14 changes: 5 additions & 9 deletions plugins/modules/ec2_vpc_route_table.py
Expand Up @@ -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)}
Expand Down

0 comments on commit 73d60e5

Please sign in to comment.