From 7e14f922622bcad31f87bbc6ac865aeb6a9c0558 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Thu, 16 Sep 2021 21:52:09 +0200 Subject: [PATCH] Split elasticache_subnet_group out --- tests/integration/targets/elasticache/aliases | 2 - .../targets/elasticache_subnet_group/aliases | 1 + .../defaults/main.yml | 42 +++ .../elasticache_subnet_group/meta/main.yml | 3 + .../elasticache_subnet_group/tasks/main.yml | 243 ++++++++++++++++++ 5 files changed, 289 insertions(+), 2 deletions(-) create mode 100644 tests/integration/targets/elasticache_subnet_group/aliases create mode 100644 tests/integration/targets/elasticache_subnet_group/defaults/main.yml create mode 100644 tests/integration/targets/elasticache_subnet_group/meta/main.yml create mode 100644 tests/integration/targets/elasticache_subnet_group/tasks/main.yml diff --git a/tests/integration/targets/elasticache/aliases b/tests/integration/targets/elasticache/aliases index 88ef7754817..5ee1d22add8 100644 --- a/tests/integration/targets/elasticache/aliases +++ b/tests/integration/targets/elasticache/aliases @@ -3,5 +3,3 @@ unstable cloud/aws - -elasticache_subnet_group diff --git a/tests/integration/targets/elasticache_subnet_group/aliases b/tests/integration/targets/elasticache_subnet_group/aliases new file mode 100644 index 00000000000..4ef4b2067d0 --- /dev/null +++ b/tests/integration/targets/elasticache_subnet_group/aliases @@ -0,0 +1 @@ +cloud/aws diff --git a/tests/integration/targets/elasticache_subnet_group/defaults/main.yml b/tests/integration/targets/elasticache_subnet_group/defaults/main.yml new file mode 100644 index 00000000000..ea8921880a9 --- /dev/null +++ b/tests/integration/targets/elasticache_subnet_group/defaults/main.yml @@ -0,0 +1,42 @@ +--- +availability_zone: '{{ ec2_availability_zone_names[0] }}' + +vpc_name: '{{ resource_prefix }}' +subnet_name_a: '{{ resource_prefix }}-a' +subnet_name_b: '{{ resource_prefix }}-b' +subnet_name_c: '{{ resource_prefix }}-c' +subnet_name_d: '{{ resource_prefix }}-d' + +vpc_cidr: '10.{{ 256 | random(seed=resource_prefix) }}.0.0/16' +subnet_cidr_a: '10.{{ 256 | random(seed=resource_prefix) }}.1.0/24' +subnet_cidr_b: '10.{{ 256 | random(seed=resource_prefix) }}.2.0/24' +subnet_cidr_c: '10.{{ 256 | random(seed=resource_prefix) }}.3.0/24' +subnet_cidr_d: '10.{{ 256 | random(seed=resource_prefix) }}.4.0/24' + +subnet_zone_a: '{{ ec2_availability_zone_names[0] }}' +subnet_zone_b: '{{ ec2_availability_zone_names[1] }}' +subnet_zone_c: '{{ ec2_availability_zone_names[0] }}' +subnet_zone_d: '{{ ec2_availability_zone_names[1] }}' + +group_name: '{{ resource_prefix }}' +description_default: 'Subnet Description' +description_updated: 'updated subnet description' + +# Tagging not currently supported, planned with boto3 upgrade +tags_default: + snake_case_key: snake_case_value + camelCaseKey: camelCaseValue + PascalCaseKey: PascalCaseValue + 'key with spaces': value with spaces + 'Upper With Spaces': Upper With Spaces + +partial_tags: + snake_case_key: snake_case_value + camelCaseKey: camelCaseValue + +updated_tags: + updated_snake_case_key: updated_snake_case_value + updatedCamelCaseKey: updatedCamelCaseValue + UpdatedPascalCaseKey: UpdatedPascalCaseValue + 'updated key with spaces': updated value with spaces + 'updated Upper With Spaces': Updated Upper With Spaces diff --git a/tests/integration/targets/elasticache_subnet_group/meta/main.yml b/tests/integration/targets/elasticache_subnet_group/meta/main.yml new file mode 100644 index 00000000000..930e8622824 --- /dev/null +++ b/tests/integration/targets/elasticache_subnet_group/meta/main.yml @@ -0,0 +1,3 @@ +dependencies: + - prepare_tests + - setup_ec2_facts diff --git a/tests/integration/targets/elasticache_subnet_group/tasks/main.yml b/tests/integration/targets/elasticache_subnet_group/tasks/main.yml new file mode 100644 index 00000000000..3f2774b2b17 --- /dev/null +++ b/tests/integration/targets/elasticache_subnet_group/tasks/main.yml @@ -0,0 +1,243 @@ +--- +# elasticache_subnet_group integration tests +# +# Current module limitations: +# - check_mode not supported +# - Tagging not supported +# - Returned values *very* limited (almost none) +# +- 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 }}' + block: + # ============================================================ + # Setup infra needed for tests + - name: create a VPC + ec2_vpc_net: + state: present + name: '{{ vpc_name }}' + cidr_block: '{{ vpc_cidr }}' + tags: + TestPrefix: '{{ resource_prefix }}' + register: vpc_result + + - name: create subnets + ec2_vpc_subnet: + state: present + cidr: '{{ item.cidr }}' + az: '{{ item.zone }}' + vpc_id: '{{ vpc_result.vpc.id }}' + tags: + Name: '{{ item.name }}' + TestPrefix: '{{ resource_prefix }}' + register: vpc_subnet_create + loop: + - name: '{{ subnet_name_a }}' + cidr: '{{ subnet_cidr_a }}' + zone: '{{ subnet_zone_a }}' + - name: '{{ subnet_name_b }}' + cidr: '{{ subnet_cidr_b }}' + zone: '{{ subnet_zone_b }}' + - name: '{{ subnet_name_c }}' + cidr: '{{ subnet_cidr_c }}' + zone: '{{ subnet_zone_c }}' + - name: '{{ subnet_name_d }}' + cidr: '{{ subnet_cidr_d }}' + zone: '{{ subnet_zone_d }}' + + - name: Store IDs of subnets and VPC + set_fact: + vpc_id: '{{ vpc_result.vpc.id }}' + subnet_id_a: '{{ vpc_subnet_create.results[0].subnet.id }}' + subnet_id_b: '{{ vpc_subnet_create.results[1].subnet.id }}' + subnet_id_c: '{{ vpc_subnet_create.results[2].subnet.id }}' + subnet_id_d: '{{ vpc_subnet_create.results[3].subnet.id }}' + # ============================================================ + + - name: Create Subnet Group + elasticache_subnet_group: + state: present + name: '{{ group_name }}' + description: '{{ description_default }}' + subnets: + - '{{ subnet_id_a }}' + - '{{ subnet_id_b }}' + register: create_group + + - name: Check result - Create Subnet Group + assert: + that: + - create_group is successful + - create_group is changed + #- '"group" in create_group' + #- '"name" in create_group.group' + #- '"vpc_id" in create_group.group' + #- create_group.group.name == group_name + #- create_group.group.vpc_id == vpc_id + + - name: Create Subnet Group - idempotency + elasticache_subnet_group: + state: present + name: '{{ group_name }}' + description: '{{ description_default }}' + subnets: + - '{{ subnet_id_a }}' + - '{{ subnet_id_b }}' + register: create_group + + - name: Check result - Create Subnet Group - idempotency + assert: + that: + - create_group is successful + - create_group is not changed + #- '"group" in create_group' + #- '"name" in create_group.group' + #- '"vpc_id" in create_group.group' + #- create_group.group.name == group_name + #- create_group.group.vpc_id == vpc_id + + # ============================================================ + + - name: Update Subnet Group Description + elasticache_subnet_group: + state: present + name: '{{ group_name }}' + description: '{{ description_updated }}' + subnets: + - '{{ subnet_id_a }}' + - '{{ subnet_id_b }}' + register: update_description + + - name: Check result - Update Subnet Group Description + assert: + that: + - update_description is successful + - update_description is changed + #- '"group" in update_description' + #- '"name" in update_description.group' + #- '"vpc_id" in update_description.group' + #- update_description.group.name == group_name + #- update_description.group.vpc_id == vpc_id + + - name: Update Subnet Group Description - idempotency + elasticache_subnet_group: + state: present + name: '{{ group_name }}' + description: '{{ description_updated }}' + subnets: + - '{{ subnet_id_a }}' + - '{{ subnet_id_b }}' + register: update_description + + - name: Check result - Update Subnet Group Description - idempotency + assert: + that: + - update_description is successful + - update_description is not changed + #- '"group" in update_description' + #- '"name" in update_description.group' + #- '"vpc_id" in update_description.group' + #- update_description.group.name == group_name + #- update_description.group.vpc_id == vpc_id + + # ============================================================ + + - name: Update Subnet Group subnets + elasticache_subnet_group: + state: present + name: '{{ group_name }}' + description: '{{ description_updated }}' + subnets: + - '{{ subnet_id_c }}' + - '{{ subnet_id_d }}' + register: update_subnets + + - name: Check result - Update Subnet Group subnets + assert: + that: + - update_subnets is successful + - update_subnets is changed + #- '"group" in update_subnets' + #- '"name" in update_subnets.group' + #- '"vpc_id" in update_subnets.group' + #- update_subnets.group.name == group_name + #- update_subnets.group.vpc_id == vpc_id + + - name: Update Subnet Group subnets - idempotency + elasticache_subnet_group: + state: present + name: '{{ group_name }}' + description: '{{ description_updated }}' + subnets: + - '{{ subnet_id_c }}' + - '{{ subnet_id_d }}' + register: update_subnets + + - name: Check result - Update Subnet Group subnets - idempotency + assert: + that: + - update_subnets is successful + - update_subnets is not changed + #- '"group" in update_subnets' + #- '"name" in update_subnets.group' + #- '"vpc_id" in update_subnets.group' + #- update_subnets.group.name == group_name + #- update_subnets.group.vpc_id == vpc_id + + # ============================================================ + + - name: Delete Subnet Group + elasticache_subnet_group: + state: absent + name: '{{ group_name }}' + register: delete_group + + - name: Check result - Delete Subnet Group + assert: + that: + - delete_group is changed + + - name: Delete Subnet Group - idempotency + elasticache_subnet_group: + state: absent + name: '{{ group_name }}' + register: delete_group + + - name: Check result - Delete Subnet Group - idempotency + assert: + that: + - delete_group is not changed + + always: + + ################################################ + # TEARDOWN STARTS HERE + ################################################ + + - name: Delete Subnet Group + elasticache_subnet_group: + state: absent + name: '{{ group_name }}' + ignore_errors: True + + - name: tidy up subnet + ec2_vpc_subnet: + state: absent + cidr: '{{ item }}' + vpc_id: '{{ vpc_result.vpc.id }}' + loop: + - '{{ subnet_cidr_a }}' + - '{{ subnet_cidr_b }}' + - '{{ subnet_cidr_c }}' + - '{{ subnet_cidr_d }}' + ignore_errors: True + + - name: tidy up VPC + ec2_vpc_net: + state: absent + name: '{{ vpc_name }}' + cidr_block: '{{ vpc_cidr }}' + ignore_errors: True