From 7251f4cf152adef53323378254fbd0043d577e9d Mon Sep 17 00:00:00 2001 From: Stefan Horning Date: Fri, 12 Feb 2021 15:20:54 +0100 Subject: [PATCH 01/16] Fix KeyError: SecurityGroup in elasticache module. Also improve docs a little --- plugins/modules/elasticache.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/elasticache.py b/plugins/modules/elasticache.py index 93804562f2e..c292dbdc524 100644 --- a/plugins/modules/elasticache.py +++ b/plugins/modules/elasticache.py @@ -74,7 +74,7 @@ elements: str cache_security_groups: description: - - A list of cache security group names to associate with this cache cluster. Must be an empty list if inside a VPC. + - A list of cache security group names to associate with this cache cluster. Don't use if your Cache is inside a VPC. In that case use I(security_group_ids) instead! type: list elements: str zone: @@ -393,7 +393,7 @@ def _requires_modification(self): # check vpc security groups if self.security_group_ids: vpc_security_groups = [] - security_groups = self.data['SecurityGroups'] or [] + security_groups = self.data.get('SecurityGroups', []) for sg in security_groups: vpc_security_groups.append(sg['SecurityGroupId']) if set(vpc_security_groups) != set(self.security_group_ids): From 6ab3f027d71770517dd85f9384937243798cc7bd Mon Sep 17 00:00:00 2001 From: Stefan Horning Date: Fri, 12 Feb 2021 16:39:33 +0100 Subject: [PATCH 02/16] Shorter line --- plugins/modules/elasticache.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/modules/elasticache.py b/plugins/modules/elasticache.py index c292dbdc524..53e72f664b4 100644 --- a/plugins/modules/elasticache.py +++ b/plugins/modules/elasticache.py @@ -74,7 +74,8 @@ elements: str cache_security_groups: description: - - A list of cache security group names to associate with this cache cluster. Don't use if your Cache is inside a VPC. In that case use I(security_group_ids) instead! + - A list of cache security group names to associate with this cache cluster. + - Don't use if your Cache is inside a VPC. In that case use I(security_group_ids) instead! type: list elements: str zone: From cd9c9fd8700897dd5ae12fad163309e275596590 Mon Sep 17 00:00:00 2001 From: Stefan Horning Date: Fri, 12 Feb 2021 17:08:10 +0100 Subject: [PATCH 03/16] Added simple integration test for elasticache module --- tests/integration/targets/elasticache/aliases | 2 ++ .../targets/elasticache/defaults/main.yml | 1 + .../targets/elasticache/tasks/main.yml | 32 +++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 tests/integration/targets/elasticache/aliases create mode 100644 tests/integration/targets/elasticache/defaults/main.yml create mode 100644 tests/integration/targets/elasticache/tasks/main.yml diff --git a/tests/integration/targets/elasticache/aliases b/tests/integration/targets/elasticache/aliases new file mode 100644 index 00000000000..6e3860bee23 --- /dev/null +++ b/tests/integration/targets/elasticache/aliases @@ -0,0 +1,2 @@ +cloud/aws +shippable/aws/group2 diff --git a/tests/integration/targets/elasticache/defaults/main.yml b/tests/integration/targets/elasticache/defaults/main.yml new file mode 100644 index 00000000000..ed97d539c09 --- /dev/null +++ b/tests/integration/targets/elasticache/defaults/main.yml @@ -0,0 +1 @@ +--- diff --git a/tests/integration/targets/elasticache/tasks/main.yml b/tests/integration/targets/elasticache/tasks/main.yml new file mode 100644 index 00000000000..f985a120fd4 --- /dev/null +++ b/tests/integration/targets/elasticache/tasks/main.yml @@ -0,0 +1,32 @@ +--- + +- name: Integration testing for the elasticache module + module_defaults: + group/aws: + aws_access_key: '{{ aws_access_key }}' + aws_secret_key: '{{ aws_secret_key }}' + security_token: '{{ security_token | default(omit) }}' + region: '{{ aws_region }}' + collections: + - amazon.aws + block: + + - name: Create Redis Server on Elasticache + elasticache: + name: elasticache-module-redis-test + engine: redis + node_type: cache.t3.micro + num_nodes: 1 + state: present + register: elasticache_redis + + - name: Assert that task worked + assert: + that: + elasticache_redis is defined + elasticache_redis is changed + elasticache_redis.elasticache.data is defined + elasticache_redis.elasticache.name == "elasticache-module-redis-test" + + + From 50c8d701a021b8a68ccf894737f9db26e31b3e78 Mon Sep 17 00:00:00 2001 From: Stefan Horning Date: Mon, 15 Feb 2021 10:34:01 +0100 Subject: [PATCH 04/16] Add changelog fragment for Elasticache module change. Add integration tests for Elasticache module. --- .../fragments/410-elasticache-fixes.yml | 5 ++ tests/integration/targets/elasticache/aliases | 1 + .../targets/elasticache/defaults/main.yml | 4 + .../targets/elasticache/tasks/main.yml | 82 +++++++++++++++++-- 4 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 changelogs/fragments/410-elasticache-fixes.yml diff --git a/changelogs/fragments/410-elasticache-fixes.yml b/changelogs/fragments/410-elasticache-fixes.yml new file mode 100644 index 00000000000..939b19ab6f2 --- /dev/null +++ b/changelogs/fragments/410-elasticache-fixes.yml @@ -0,0 +1,5 @@ +--- +bugfixes: + - elasticache - Fix issue when updating security group (KeyError) +minor_changes: + - elasticache - Improve docs a little, add intgration tests diff --git a/tests/integration/targets/elasticache/aliases b/tests/integration/targets/elasticache/aliases index 6e3860bee23..1d417b8e513 100644 --- a/tests/integration/targets/elasticache/aliases +++ b/tests/integration/targets/elasticache/aliases @@ -1,2 +1,3 @@ cloud/aws shippable/aws/group2 +elasticache_subnet_group diff --git a/tests/integration/targets/elasticache/defaults/main.yml b/tests/integration/targets/elasticache/defaults/main.yml index ed97d539c09..a6f7649c4f3 100644 --- a/tests/integration/targets/elasticache/defaults/main.yml +++ b/tests/integration/targets/elasticache/defaults/main.yml @@ -1 +1,5 @@ --- + +elasticache_redis_test_name: elasticache-module-redis-test +elasticache_subnet_group_name: elasticache-test-vpc-subnet-group +elasticache_redis_port: 6379 diff --git a/tests/integration/targets/elasticache/tasks/main.yml b/tests/integration/targets/elasticache/tasks/main.yml index f985a120fd4..92d76604a18 100644 --- a/tests/integration/targets/elasticache/tasks/main.yml +++ b/tests/integration/targets/elasticache/tasks/main.yml @@ -10,12 +10,47 @@ collections: - amazon.aws block: + # == Dependency setup == - - name: Create Redis Server on Elasticache - elasticache: - name: elasticache-module-redis-test + - name: Create VPC to launch Elasticache instances into + amazon.aws.ec2_vpc_net: + name: elasticache-test-vpc + cidr_block: 10.31.0.0/16 + state: present + register: elasticache_vpc + + - name: Create subnet 1 in this VPC to launch Elasticache instances into + amazon.aws.ec2_vpc_subnet: + vpc_id: "{{ elasticache_vpc.vpc.id }}" + cidr: 10.31.1.0/24 + state: present + register: elasticache_vpc_subnet_1 + + - name: Create subnet 2 in this VPC to launch Elasticache instances into + amazon.aws.ec2_vpc_subnet: + vpc_id: "{{ elasticache_vpc.vpc.id }}" + cidr: 10.31.2.0/24 + state: present + register: elasticache_vpc_subnet_2 + + - name: Create Elasticache Subnet Group (grouping two subnets together) + community.aws.elasticache_subnet_group: + name: "{{ elasticache_subnet_group_name }}" + description: Subnet group grouping together both VPC subnets for Elasticache Test setup + subnets: + - "{{ elasticache_vpc_subnet_1.subnet.id }}" + - "{{ elasticache_vpc_subnet_2.subnet.id }}" + state: present + + # == Actual testing of the elasticache module == + + - name: Create Redis Server on Elasticache in VPC subnets + community.aws.elasticache: + name: "{{ elasticache_redis_test_name }}" engine: redis node_type: cache.t3.micro + cache_port: "{{ elasticache_redis_port }}" + cache_subnet_group: "{{ elasticache_subnet_group_name }}" num_nodes: 1 state: present register: elasticache_redis @@ -23,10 +58,47 @@ - name: Assert that task worked assert: that: - elasticache_redis is defined elasticache_redis is changed elasticache_redis.elasticache.data is defined - elasticache_redis.elasticache.name == "elasticache-module-redis-test" + elasticache_redis.elasticache.name == "{{ elasticache_redis_test_name }}" + elasticache_redis.elasticache.data.CacheSubnetGroupName == "{{ elasticache_subnet_group_name }}" + - name: Add security group for Redis access in Elasticache + amazon.aws.ec2_group: + name: elasticache-test-redis-sg + description: Allow access to Elasticache Redis for testing EC module + vpc_id: "{{ elasticache_vpc.vpc.id }}" + rules: + - proto: tcp + from_port: "{{ elasticache_redis_port }}" + to_port: "{{ elasticache_redis_port }}" + cidr: 10.31.0.0/16 + register: elasticache_redis_sg + - name: Update Redis Elasticache config with security group (to if changes to existing setup work) + community.aws.elasticache: + name: "{{ elasticache_test_name }}" + engine: redis + node_type: cache.t3.micro + num_nodes: 1 + cache_port: "{{ elasticache_redis_port }}" + cache_subnet_group: elasticache-test-vpc-subnet-group + security_group_ids: "{{ elasticache_redis_sg.group_id }}" + state: present + register: elasticache_redis_new + - name: Assert that task worked + assert: + that: + elasticache_redis_new is changed + elasticache_redis_new.elasticache.data is defined + elasticache_redis_new.elasticache.data.Engine == "redis" + elasticache_redis_new.elasticache.data.SecurityGroups.0.SecurityGroupId == "{{ elasticache_redis_sg.group_id }}" + + always: + + - name: Make sure test redis is deleted again + community.aws.elasticache: + name: "{{ elasticache_test_name }}" + engine: redis + state: absent From 7d6ecb7cd58afb8cbadc38b00948b0e223269024 Mon Sep 17 00:00:00 2001 From: Stefan Horning Date: Mon, 15 Feb 2021 10:50:21 +0100 Subject: [PATCH 05/16] Complete cleanup all integration test resources for elasticache --- .../targets/elasticache/tasks/main.yml | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/integration/targets/elasticache/tasks/main.yml b/tests/integration/targets/elasticache/tasks/main.yml index 92d76604a18..62e4aa47661 100644 --- a/tests/integration/targets/elasticache/tasks/main.yml +++ b/tests/integration/targets/elasticache/tasks/main.yml @@ -97,8 +97,25 @@ always: - - name: Make sure test redis is deleted again + # == Cleanup == + + - name: Make sure test Redis is deleted again from Elasticache community.aws.elasticache: name: "{{ elasticache_test_name }}" engine: redis state: absent + + - name: Make sure Subnet group is deleted again + community.aws.elasticache_subnet_group: + name: "{{ elasticache_subnet_group_name }}" + state: absent + + - name: Make sure VPC SG is deleted again + amazon.aws.ec2_group: + name: elasticache-test-redis-sg + state: absent + + - name: Make sure VPC is deleted again (should also delete subnets?) + amazon.aws.ec2_vpc_net: + name: elasticache-test-vpc + state: absent From 566bd22c39dc5584afc0bd281093ef8941bd6e87 Mon Sep 17 00:00:00 2001 From: Stefan Horning Date: Mon, 15 Feb 2021 10:54:24 +0100 Subject: [PATCH 06/16] Fix variable names --- tests/integration/targets/elasticache/tasks/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/targets/elasticache/tasks/main.yml b/tests/integration/targets/elasticache/tasks/main.yml index 62e4aa47661..327fda5abdc 100644 --- a/tests/integration/targets/elasticache/tasks/main.yml +++ b/tests/integration/targets/elasticache/tasks/main.yml @@ -77,7 +77,7 @@ - name: Update Redis Elasticache config with security group (to if changes to existing setup work) community.aws.elasticache: - name: "{{ elasticache_test_name }}" + name: "{{ elasticache_redis.name }}" engine: redis node_type: cache.t3.micro num_nodes: 1 @@ -101,7 +101,7 @@ - name: Make sure test Redis is deleted again from Elasticache community.aws.elasticache: - name: "{{ elasticache_test_name }}" + name: "{{ elasticache_redis_test_name }}" engine: redis state: absent From 717f51cbb9402e77e52634f7a3e4c39fb286071f Mon Sep 17 00:00:00 2001 From: Stefan Horning Date: Mon, 15 Feb 2021 11:11:43 +0100 Subject: [PATCH 07/16] Attach region flag to all tasks in integration test, as somehow region wasn't picke up from test wide config --- tests/integration/targets/elasticache/tasks/main.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/integration/targets/elasticache/tasks/main.yml b/tests/integration/targets/elasticache/tasks/main.yml index 327fda5abdc..9660143a1c2 100644 --- a/tests/integration/targets/elasticache/tasks/main.yml +++ b/tests/integration/targets/elasticache/tasks/main.yml @@ -17,6 +17,7 @@ name: elasticache-test-vpc cidr_block: 10.31.0.0/16 state: present + region: "{{ aws_region }}" register: elasticache_vpc - name: Create subnet 1 in this VPC to launch Elasticache instances into @@ -24,6 +25,7 @@ vpc_id: "{{ elasticache_vpc.vpc.id }}" cidr: 10.31.1.0/24 state: present + region: "{{ aws_region }}" register: elasticache_vpc_subnet_1 - name: Create subnet 2 in this VPC to launch Elasticache instances into @@ -31,6 +33,7 @@ vpc_id: "{{ elasticache_vpc.vpc.id }}" cidr: 10.31.2.0/24 state: present + region: "{{ aws_region }}" register: elasticache_vpc_subnet_2 - name: Create Elasticache Subnet Group (grouping two subnets together) @@ -41,6 +44,7 @@ - "{{ elasticache_vpc_subnet_1.subnet.id }}" - "{{ elasticache_vpc_subnet_2.subnet.id }}" state: present + region: "{{ aws_region }}" # == Actual testing of the elasticache module == @@ -53,6 +57,7 @@ cache_subnet_group: "{{ elasticache_subnet_group_name }}" num_nodes: 1 state: present + region: "{{ aws_region }}" register: elasticache_redis - name: Assert that task worked @@ -73,6 +78,7 @@ from_port: "{{ elasticache_redis_port }}" to_port: "{{ elasticache_redis_port }}" cidr: 10.31.0.0/16 + region: "{{ aws_region }}" register: elasticache_redis_sg - name: Update Redis Elasticache config with security group (to if changes to existing setup work) @@ -84,6 +90,7 @@ cache_port: "{{ elasticache_redis_port }}" cache_subnet_group: elasticache-test-vpc-subnet-group security_group_ids: "{{ elasticache_redis_sg.group_id }}" + region: "{{ aws_region }}" state: present register: elasticache_redis_new @@ -103,19 +110,23 @@ community.aws.elasticache: name: "{{ elasticache_redis_test_name }}" engine: redis + region: "{{ aws_region }}" state: absent - name: Make sure Subnet group is deleted again community.aws.elasticache_subnet_group: name: "{{ elasticache_subnet_group_name }}" + region: "{{ aws_region }}" state: absent - name: Make sure VPC SG is deleted again amazon.aws.ec2_group: name: elasticache-test-redis-sg + region: "{{ aws_region }}" state: absent - name: Make sure VPC is deleted again (should also delete subnets?) amazon.aws.ec2_vpc_net: name: elasticache-test-vpc + region: "{{ aws_region }}" state: absent From 25623438223389955ebfb1c68db86e8a28a5f546 Mon Sep 17 00:00:00 2001 From: Stefan Horning Date: Tue, 16 Feb 2021 16:10:32 +0100 Subject: [PATCH 08/16] Remove FQDN from modules names in tests in an attempt to fix AWS params/credentials passing --- .../targets/elasticache/defaults/main.yml | 4 +-- .../targets/elasticache/tasks/main.yml | 33 +++++++------------ 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/tests/integration/targets/elasticache/defaults/main.yml b/tests/integration/targets/elasticache/defaults/main.yml index a6f7649c4f3..5be91047b4d 100644 --- a/tests/integration/targets/elasticache/defaults/main.yml +++ b/tests/integration/targets/elasticache/defaults/main.yml @@ -1,5 +1,5 @@ --- -elasticache_redis_test_name: elasticache-module-redis-test -elasticache_subnet_group_name: elasticache-test-vpc-subnet-group +elasticache_redis_test_name: "{{ resource_prefix }}-elasticache-module-redis-test" +elasticache_subnet_group_name: "{{ resource_prefix }}-elasticache-test-vpc-subnet-group" elasticache_redis_port: 6379 diff --git a/tests/integration/targets/elasticache/tasks/main.yml b/tests/integration/targets/elasticache/tasks/main.yml index 9660143a1c2..62ad2d91cb4 100644 --- a/tests/integration/targets/elasticache/tasks/main.yml +++ b/tests/integration/targets/elasticache/tasks/main.yml @@ -13,43 +13,39 @@ # == Dependency setup == - name: Create VPC to launch Elasticache instances into - amazon.aws.ec2_vpc_net: + ec2_vpc_net: name: elasticache-test-vpc cidr_block: 10.31.0.0/16 state: present - region: "{{ aws_region }}" register: elasticache_vpc - name: Create subnet 1 in this VPC to launch Elasticache instances into - amazon.aws.ec2_vpc_subnet: + ec2_vpc_subnet: vpc_id: "{{ elasticache_vpc.vpc.id }}" cidr: 10.31.1.0/24 state: present - region: "{{ aws_region }}" register: elasticache_vpc_subnet_1 - name: Create subnet 2 in this VPC to launch Elasticache instances into - amazon.aws.ec2_vpc_subnet: + ec2_vpc_subnet: vpc_id: "{{ elasticache_vpc.vpc.id }}" cidr: 10.31.2.0/24 state: present - region: "{{ aws_region }}" register: elasticache_vpc_subnet_2 - name: Create Elasticache Subnet Group (grouping two subnets together) - community.aws.elasticache_subnet_group: + elasticache_subnet_group: name: "{{ elasticache_subnet_group_name }}" description: Subnet group grouping together both VPC subnets for Elasticache Test setup subnets: - "{{ elasticache_vpc_subnet_1.subnet.id }}" - "{{ elasticache_vpc_subnet_2.subnet.id }}" state: present - region: "{{ aws_region }}" # == Actual testing of the elasticache module == - name: Create Redis Server on Elasticache in VPC subnets - community.aws.elasticache: + elasticache: name: "{{ elasticache_redis_test_name }}" engine: redis node_type: cache.t3.micro @@ -57,7 +53,6 @@ cache_subnet_group: "{{ elasticache_subnet_group_name }}" num_nodes: 1 state: present - region: "{{ aws_region }}" register: elasticache_redis - name: Assert that task worked @@ -69,7 +64,7 @@ elasticache_redis.elasticache.data.CacheSubnetGroupName == "{{ elasticache_subnet_group_name }}" - name: Add security group for Redis access in Elasticache - amazon.aws.ec2_group: + ec2_group: name: elasticache-test-redis-sg description: Allow access to Elasticache Redis for testing EC module vpc_id: "{{ elasticache_vpc.vpc.id }}" @@ -78,11 +73,10 @@ from_port: "{{ elasticache_redis_port }}" to_port: "{{ elasticache_redis_port }}" cidr: 10.31.0.0/16 - region: "{{ aws_region }}" register: elasticache_redis_sg - name: Update Redis Elasticache config with security group (to if changes to existing setup work) - community.aws.elasticache: + elasticache: name: "{{ elasticache_redis.name }}" engine: redis node_type: cache.t3.micro @@ -90,7 +84,6 @@ cache_port: "{{ elasticache_redis_port }}" cache_subnet_group: elasticache-test-vpc-subnet-group security_group_ids: "{{ elasticache_redis_sg.group_id }}" - region: "{{ aws_region }}" state: present register: elasticache_redis_new @@ -107,26 +100,22 @@ # == Cleanup == - name: Make sure test Redis is deleted again from Elasticache - community.aws.elasticache: + elasticache: name: "{{ elasticache_redis_test_name }}" engine: redis - region: "{{ aws_region }}" state: absent - name: Make sure Subnet group is deleted again - community.aws.elasticache_subnet_group: + elasticache_subnet_group: name: "{{ elasticache_subnet_group_name }}" - region: "{{ aws_region }}" state: absent - name: Make sure VPC SG is deleted again - amazon.aws.ec2_group: + ec2_group: name: elasticache-test-redis-sg - region: "{{ aws_region }}" state: absent - name: Make sure VPC is deleted again (should also delete subnets?) - amazon.aws.ec2_vpc_net: + ec2_vpc_net: name: elasticache-test-vpc - region: "{{ aws_region }}" state: absent From 1f85d1110c3e5234899ce4b1c8e3db12162f018c Mon Sep 17 00:00:00 2001 From: Stefan Horning Date: Tue, 16 Feb 2021 16:15:01 +0100 Subject: [PATCH 09/16] Also prefix vpc in test with resource_prefix. Use variable for elasticache subnet group in another place --- tests/integration/targets/elasticache/tasks/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/integration/targets/elasticache/tasks/main.yml b/tests/integration/targets/elasticache/tasks/main.yml index 62ad2d91cb4..c8080c1afcd 100644 --- a/tests/integration/targets/elasticache/tasks/main.yml +++ b/tests/integration/targets/elasticache/tasks/main.yml @@ -14,7 +14,7 @@ - name: Create VPC to launch Elasticache instances into ec2_vpc_net: - name: elasticache-test-vpc + name: "{{ resource_prefix }}-elasticache-test-vpc" cidr_block: 10.31.0.0/16 state: present register: elasticache_vpc @@ -50,7 +50,7 @@ engine: redis node_type: cache.t3.micro cache_port: "{{ elasticache_redis_port }}" - cache_subnet_group: "{{ elasticache_subnet_group_name }}" + cache_subnet_group: "{{ elasticache_subnet_group_name }}" num_nodes: 1 state: present register: elasticache_redis @@ -82,7 +82,7 @@ node_type: cache.t3.micro num_nodes: 1 cache_port: "{{ elasticache_redis_port }}" - cache_subnet_group: elasticache-test-vpc-subnet-group + cache_subnet_group: "{{ elasticache_subnet_group_name }}" security_group_ids: "{{ elasticache_redis_sg.group_id }}" state: present register: elasticache_redis_new From e59b5f93ea651644ea683b4a84e77691233914d7 Mon Sep 17 00:00:00 2001 From: Stefan Horning Date: Wed, 17 Feb 2021 10:54:05 +0100 Subject: [PATCH 10/16] More improvements in elasticache integration tests (use variables for naming everywhere) --- .../targets/elasticache/defaults/main.yml | 5 +++++ .../targets/elasticache/tasks/main.yml | 16 ++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/tests/integration/targets/elasticache/defaults/main.yml b/tests/integration/targets/elasticache/defaults/main.yml index 5be91047b4d..0f16199726c 100644 --- a/tests/integration/targets/elasticache/defaults/main.yml +++ b/tests/integration/targets/elasticache/defaults/main.yml @@ -1,5 +1,10 @@ --- +vpc_name: "{{ resource_prefix }}-elasticache-test-vpc" +vpc_seed: '{{ resource_prefix }}' +vpc_cidr_prefix: '10.{{ 256 | random(seed=vpc_seed) }}' + +elasticache_redis_sg_name: "{{ resource_prefix }}-elasticache-test-redis-sg" elasticache_redis_test_name: "{{ resource_prefix }}-elasticache-module-redis-test" elasticache_subnet_group_name: "{{ resource_prefix }}-elasticache-test-vpc-subnet-group" elasticache_redis_port: 6379 diff --git a/tests/integration/targets/elasticache/tasks/main.yml b/tests/integration/targets/elasticache/tasks/main.yml index c8080c1afcd..15f76cae841 100644 --- a/tests/integration/targets/elasticache/tasks/main.yml +++ b/tests/integration/targets/elasticache/tasks/main.yml @@ -14,22 +14,22 @@ - name: Create VPC to launch Elasticache instances into ec2_vpc_net: - name: "{{ resource_prefix }}-elasticache-test-vpc" - cidr_block: 10.31.0.0/16 + name: "{{ vpc_name }}" + cidr_block: "{{ vpc_cidr_prefix }}.0.0/16" state: present register: elasticache_vpc - name: Create subnet 1 in this VPC to launch Elasticache instances into ec2_vpc_subnet: vpc_id: "{{ elasticache_vpc.vpc.id }}" - cidr: 10.31.1.0/24 + cidr: "{{ vpc_cidr_prefix }}.1.0/24" state: present register: elasticache_vpc_subnet_1 - name: Create subnet 2 in this VPC to launch Elasticache instances into ec2_vpc_subnet: vpc_id: "{{ elasticache_vpc.vpc.id }}" - cidr: 10.31.2.0/24 + cidr: "{{ vpc_cidr_prefix }}.2.0/24" state: present register: elasticache_vpc_subnet_2 @@ -65,9 +65,9 @@ - name: Add security group for Redis access in Elasticache ec2_group: - name: elasticache-test-redis-sg + name: "{{ elasticache_redis_sg_name }}" description: Allow access to Elasticache Redis for testing EC module - vpc_id: "{{ elasticache_vpc.vpc.id }}" + vpc_id: "{{ elasticache_vpc.vpc.id }}" rules: - proto: tcp from_port: "{{ elasticache_redis_port }}" @@ -112,10 +112,10 @@ - name: Make sure VPC SG is deleted again ec2_group: - name: elasticache-test-redis-sg + name: "{{ elasticache_redis_sg_name }}" state: absent - name: Make sure VPC is deleted again (should also delete subnets?) ec2_vpc_net: - name: elasticache-test-vpc + name: "{{ vpc_name }}" state: absent From 9608cafb711b1894235e43aeec254f1eb96df4e0 Mon Sep 17 00:00:00 2001 From: Stefan Horning Date: Fri, 26 Feb 2021 11:47:01 +0100 Subject: [PATCH 11/16] Fixes in elasticache integration tests --- .../targets/elasticache/defaults/main.yml | 2 +- .../targets/elasticache/tasks/main.yml | 21 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/tests/integration/targets/elasticache/defaults/main.yml b/tests/integration/targets/elasticache/defaults/main.yml index 0f16199726c..1e1f60c90bd 100644 --- a/tests/integration/targets/elasticache/defaults/main.yml +++ b/tests/integration/targets/elasticache/defaults/main.yml @@ -5,6 +5,6 @@ vpc_seed: '{{ resource_prefix }}' vpc_cidr_prefix: '10.{{ 256 | random(seed=vpc_seed) }}' elasticache_redis_sg_name: "{{ resource_prefix }}-elasticache-test-redis-sg" -elasticache_redis_test_name: "{{ resource_prefix }}-elasticache-module-redis-test" +elasticache_redis_test_name: "{{ resource_prefix }}-redis-test" elasticache_subnet_group_name: "{{ resource_prefix }}-elasticache-test-vpc-subnet-group" elasticache_redis_port: 6379 diff --git a/tests/integration/targets/elasticache/tasks/main.yml b/tests/integration/targets/elasticache/tasks/main.yml index 15f76cae841..337a8c8cb52 100644 --- a/tests/integration/targets/elasticache/tasks/main.yml +++ b/tests/integration/targets/elasticache/tasks/main.yml @@ -58,10 +58,10 @@ - name: Assert that task worked assert: that: - elasticache_redis is changed - elasticache_redis.elasticache.data is defined - elasticache_redis.elasticache.name == "{{ elasticache_redis_test_name }}" - elasticache_redis.elasticache.data.CacheSubnetGroupName == "{{ elasticache_subnet_group_name }}" + - elasticache_redis is changed + - elasticache_redis.elasticache.data is defined + - elasticache_redis.elasticache.name == "{{ elasticache_redis_test_name }}" + - elasticache_redis.elasticache.data.CacheSubnetGroupName == "{{ elasticache_subnet_group_name }}" - name: Add security group for Redis access in Elasticache ec2_group: @@ -72,12 +72,12 @@ - proto: tcp from_port: "{{ elasticache_redis_port }}" to_port: "{{ elasticache_redis_port }}" - cidr: 10.31.0.0/16 + cidr_ip: 10.31.0.0/16 register: elasticache_redis_sg - name: Update Redis Elasticache config with security group (to if changes to existing setup work) elasticache: - name: "{{ elasticache_redis.name }}" + name: "{{ elasticache_redis.elasticache.name }}" engine: redis node_type: cache.t3.micro num_nodes: 1 @@ -90,10 +90,10 @@ - name: Assert that task worked assert: that: - elasticache_redis_new is changed - elasticache_redis_new.elasticache.data is defined - elasticache_redis_new.elasticache.data.Engine == "redis" - elasticache_redis_new.elasticache.data.SecurityGroups.0.SecurityGroupId == "{{ elasticache_redis_sg.group_id }}" + - elasticache_redis_new is changed + - elasticache_redis_new.elasticache.data is defined + - elasticache_redis_new.elasticache.data.Engine == "redis" + - elasticache_redis_new.elasticache.data.SecurityGroups.0.SecurityGroupId == elasticache_redis_sg.group_id always: @@ -118,4 +118,5 @@ - name: Make sure VPC is deleted again (should also delete subnets?) ec2_vpc_net: name: "{{ vpc_name }}" + cidr_block: "{{ vpc_cidr_prefix }}.0.0/16" state: absent From 8c385f4b222cc024b1e4e4401226955c4ff929e3 Mon Sep 17 00:00:00 2001 From: Stefan Horning Date: Fri, 26 Feb 2021 12:20:20 +0100 Subject: [PATCH 12/16] Fix elasticache integration test VPC clanup --- .../targets/elasticache/tasks/main.yml | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/integration/targets/elasticache/tasks/main.yml b/tests/integration/targets/elasticache/tasks/main.yml index 337a8c8cb52..0d4219384d2 100644 --- a/tests/integration/targets/elasticache/tasks/main.yml +++ b/tests/integration/targets/elasticache/tasks/main.yml @@ -105,17 +105,29 @@ engine: redis state: absent - - name: Make sure Subnet group is deleted again + - name: Make sure Elasticache Subnet group is deleted again elasticache_subnet_group: name: "{{ elasticache_subnet_group_name }}" state: absent - - name: Make sure VPC SG is deleted again + - name: Make sure Redis Security Group is deleted again ec2_group: name: "{{ elasticache_redis_sg_name }}" state: absent - - name: Make sure VPC is deleted again (should also delete subnets?) + - name: Make sure VPC subnet 1 is deleted again + ec2_vpc_subnet: + vpc_id: "{{ elasticache_vpc.vpc.id }}" + cidr: "{{ vpc_cidr_prefix }}.1.0/24" + state: absent + + - name: Make sure VPC subnet 2 is deleted again + ec2_vpc_subnet: + vpc_id: "{{ elasticache_vpc.vpc.id }}" + cidr: "{{ vpc_cidr_prefix }}.2.0/24" + state: absent + + - name: Make sure VPC is deleted again (only works if subnets were deleted) ec2_vpc_net: name: "{{ vpc_name }}" cidr_block: "{{ vpc_cidr_prefix }}.0.0/16" From bdabad57908e1605850e4dc81c2edb9e13c1e451 Mon Sep 17 00:00:00 2001 From: Stefan Horning Date: Fri, 26 Feb 2021 12:40:42 +0100 Subject: [PATCH 13/16] Fix elasticache integration test syntax --- tests/integration/targets/elasticache/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/targets/elasticache/tasks/main.yml b/tests/integration/targets/elasticache/tasks/main.yml index 0d4219384d2..915c9ddf03c 100644 --- a/tests/integration/targets/elasticache/tasks/main.yml +++ b/tests/integration/targets/elasticache/tasks/main.yml @@ -73,7 +73,7 @@ from_port: "{{ elasticache_redis_port }}" to_port: "{{ elasticache_redis_port }}" cidr_ip: 10.31.0.0/16 - register: elasticache_redis_sg + register: elasticache_redis_sg - name: Update Redis Elasticache config with security group (to if changes to existing setup work) elasticache: From d7876498452b0b5d4d37bd82fd0d1e6ed6a2bf77 Mon Sep 17 00:00:00 2001 From: Stefan Horning Date: Mon, 22 Mar 2021 09:47:03 +0100 Subject: [PATCH 14/16] Update changelogs/fragments/410-elasticache-fixes.yml Co-authored-by: Mark Chappell --- changelogs/fragments/410-elasticache-fixes.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelogs/fragments/410-elasticache-fixes.yml b/changelogs/fragments/410-elasticache-fixes.yml index 939b19ab6f2..ca5c36b208a 100644 --- a/changelogs/fragments/410-elasticache-fixes.yml +++ b/changelogs/fragments/410-elasticache-fixes.yml @@ -1,5 +1,5 @@ --- bugfixes: - - elasticache - Fix issue when updating security group (KeyError) + - elasticache - Fix ``KeyError`` issue when updating security group (https://github.com/ansible-collections/community.aws/pull/410). minor_changes: - elasticache - Improve docs a little, add intgration tests From a8591803c50067528f4fbaced93159aebdbd4922 Mon Sep 17 00:00:00 2001 From: Stefan Horning Date: Mon, 22 Mar 2021 09:47:16 +0100 Subject: [PATCH 15/16] Update changelogs/fragments/410-elasticache-fixes.yml Co-authored-by: Mark Chappell --- changelogs/fragments/410-elasticache-fixes.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelogs/fragments/410-elasticache-fixes.yml b/changelogs/fragments/410-elasticache-fixes.yml index ca5c36b208a..69e9a176e0b 100644 --- a/changelogs/fragments/410-elasticache-fixes.yml +++ b/changelogs/fragments/410-elasticache-fixes.yml @@ -2,4 +2,4 @@ bugfixes: - elasticache - Fix ``KeyError`` issue when updating security group (https://github.com/ansible-collections/community.aws/pull/410). minor_changes: - - elasticache - Improve docs a little, add intgration tests + - elasticache - Improve docs a little, add intgration tests (https://github.com/ansible-collections/community.aws/pull/410). From c233496b96c70cfc6204e75d10116a96b08d4663 Mon Sep 17 00:00:00 2001 From: Stefan Horning Date: Mon, 22 Mar 2021 09:47:23 +0100 Subject: [PATCH 16/16] Update tests/integration/targets/elasticache/aliases Co-authored-by: Mark Chappell --- tests/integration/targets/elasticache/aliases | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/integration/targets/elasticache/aliases b/tests/integration/targets/elasticache/aliases index 1d417b8e513..ce569e50624 100644 --- a/tests/integration/targets/elasticache/aliases +++ b/tests/integration/targets/elasticache/aliases @@ -1,3 +1,8 @@ +# Sometimes hit AWS capacity issues - InsufficientCacheClusterCapacity +# https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/ErrorMessages.html#ErrorMessages.INSUFFICIENT_CACHE_CLUSTER_CAPACITY +unstable + cloud/aws -shippable/aws/group2 +shippable/aws/group1 + elasticache_subnet_group