Skip to content

Commit

Permalink
Split elasticache_subnet_group out
Browse files Browse the repository at this point in the history
  • Loading branch information
tremble committed Sep 17, 2021
1 parent 095d4e4 commit 7e14f92
Show file tree
Hide file tree
Showing 5 changed files with 289 additions and 2 deletions.
2 changes: 0 additions & 2 deletions tests/integration/targets/elasticache/aliases
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@
unstable

cloud/aws

elasticache_subnet_group
1 change: 1 addition & 0 deletions tests/integration/targets/elasticache_subnet_group/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cloud/aws
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies:
- prepare_tests
- setup_ec2_facts
243 changes: 243 additions & 0 deletions tests/integration/targets/elasticache_subnet_group/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7e14f92

Please sign in to comment.