From 4187317d9cf0dcf5c1154bed60ca12b24552e63c Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Thu, 25 Mar 2021 15:43:02 +0100 Subject: [PATCH] ec2_vpc_route_table - Test idempotency with adding a route (#496) * Test idempotency with adding a route * tweak changelog to include bugfix link --- .../fragments/359-fix-ec2_vpc_route_table.yml | 2 +- .../ec2_vpc_route_table/tasks/main.yml | 36 ++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/changelogs/fragments/359-fix-ec2_vpc_route_table.yml b/changelogs/fragments/359-fix-ec2_vpc_route_table.yml index 60ca36ba8a5..61f90d9af5c 100644 --- a/changelogs/fragments/359-fix-ec2_vpc_route_table.yml +++ b/changelogs/fragments/359-fix-ec2_vpc_route_table.yml @@ -1,2 +1,2 @@ bugfixes: - - ec2_vpc_route_table - catch RouteAlreadyExists error when rerunning same task twice to make module idempotent + - ec2_vpc_route_table - catch RouteAlreadyExists error when rerunning same task twice to make module idempotent (https://github.com/ansible-collections/community.aws/issues/357). diff --git a/tests/integration/targets/ec2_vpc_route_table/tasks/main.yml b/tests/integration/targets/ec2_vpc_route_table/tasks/main.yml index 2241eba979c..3a96fed7650 100644 --- a/tests/integration/targets/ec2_vpc_route_table/tasks/main.yml +++ b/tests/integration/targets/ec2_vpc_route_table/tasks/main.yml @@ -17,7 +17,7 @@ state: present register: vpc - - name: create public subnet + - name: create subnets ec2_vpc_subnet: cidr: "{{ item.cidr }}" az: "{{ aws_region}}{{ item.az }}" @@ -170,6 +170,40 @@ - add_routes.route_table.vpc_id == "{{ vpc.vpc.id }}" - add_routes.route_table.propagating_vgws|length == 0 + - name: CHECK MODE - re-add route to public route table + ec2_vpc_route_table: + vpc_id: "{{ vpc.vpc.id }}" + tags: + Public: "true" + Name: "Public route table" + routes: + - dest: 0.0.0.0/0 + gateway_id: igw + check_mode: True + register: check_mode_results + + - name: assert a route would not be added + assert: + that: + - check_mode_results is not changed + + - name: re-add a route to public route table + ec2_vpc_route_table: + vpc_id: "{{ vpc.vpc.id }}" + tags: + Public: "true" + Name: "Public route table" + routes: + - dest: 0.0.0.0/0 + gateway_id: igw + register: add_routes + + - name: assert route table contains route + assert: + that: + - add_routes is not changed + - add_routes.route_table.routes|length == 2 + - name: CHECK MODE - add subnets to public route table ec2_vpc_route_table: vpc_id: "{{ vpc.vpc.id }}"