Skip to content

Commit

Permalink
Add integration tests for redshift_subnet_group
Browse files Browse the repository at this point in the history
  • Loading branch information
tremble committed Sep 16, 2021
1 parent 095d4e4 commit 7c7b028
Show file tree
Hide file tree
Showing 5 changed files with 295 additions and 0 deletions.
2 changes: 2 additions & 0 deletions plugins/modules/redshift_subnet_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@
group_description:
description:
- Database subnet group description.
- Required when I(state=present).
aliases: ['description']
type: str
group_subnets:
description:
- List of subnet IDs that make up the cluster subnet group.
- Required when I(state=present).
aliases: ['subnets']
type: list
elements: str
Expand Down
1 change: 1 addition & 0 deletions tests/integration/targets/redshift_subnet_group/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cloud/aws
42 changes: 42 additions & 0 deletions tests/integration/targets/redshift_subnet_group/defaults/main.yml
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
3 changes: 3 additions & 0 deletions tests/integration/targets/redshift_subnet_group/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies:
- prepare_tests
- setup_ec2_facts
247 changes: 247 additions & 0 deletions tests/integration/targets/redshift_subnet_group/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
---
# redshift_subnet_group integration tests
#
# Current module limitations:
# - check_mode not supported
# - Tagging not supported
# - Module is not idempotent
# - Returned values *very* limited
#
- 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
redshift_subnet_group:
state: present
group_name: '{{ group_name }}'
group_description: '{{ description_default }}'
group_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
redshift_subnet_group:
state: present
group_name: '{{ group_name }}'
group_description: '{{ description_default }}'
group_subnets:
- '{{ subnet_id_a }}'
- '{{ subnet_id_b }}'
register: create_group

- name: Check result - Create Subnet Group - idempotency
assert:
that:
- create_group is successful
# XXX Not idempotent
#- 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
redshift_subnet_group:
state: present
group_name: '{{ group_name }}'
group_description: '{{ description_updated }}'
group_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
redshift_subnet_group:
state: present
group_name: '{{ group_name }}'
group_description: '{{ description_updated }}'
group_subnets:
- '{{ subnet_id_a }}'
- '{{ subnet_id_b }}'
register: update_description

- name: Check result - Update Subnet Group Description - idempotency
assert:
that:
- update_description is successful
# XXX Not idempotent
#- 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
redshift_subnet_group:
state: present
group_name: '{{ group_name }}'
group_description: '{{ description_updated }}'
group_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
redshift_subnet_group:
state: present
group_name: '{{ group_name }}'
group_description: '{{ description_updated }}'
group_subnets:
- '{{ subnet_id_c }}'
- '{{ subnet_id_d }}'
register: update_subnets

- name: Check result - Update Subnet Group subnets - idempotency
assert:
that:
- update_subnets is successful
# XXX Not idempotent
#- 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
redshift_subnet_group:
state: absent
group_name: '{{ group_name }}'
register: delete_group

- name: Check result - Delete Subnet Group
assert:
that:
- delete_group is changed

- name: Delete Subnet Group - idempotency
redshift_subnet_group:
state: absent
group_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
redshift_subnet_group:
state: absent
group_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 7c7b028

Please sign in to comment.