Skip to content

Commit

Permalink
Add support for check_mode
Browse files Browse the repository at this point in the history
  • Loading branch information
tremble committed Sep 17, 2021
1 parent 24c8211 commit e6804ce
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
minor_changes:
- elasticache_subnet_group - module migrated to boto3 AWS SDK (https://github.com/ansible-collections/community.aws/pull/723).
- elasticache_subnet_group - add return values (https://github.com/ansible-collections/community.aws/pull/723).
- elasticache_subnet_group - add support for check_mode (https://github.com/ansible-collections/community.aws/pull/723).
16 changes: 15 additions & 1 deletion plugins/modules/elasticache_subnet_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ def get_subnet_group(name):


def create_subnet_group(name, description, subnets):

if module.check_mode:
return True

try:
if not description:
description = name
Expand Down Expand Up @@ -168,6 +172,9 @@ def update_subnet_group(subnet_group, name, description, subnets):
if not update_params:
return False

if module.check_mode:
return True

try:
client.modify_cache_subnet_group(
aws_retry=True,
Expand All @@ -181,6 +188,10 @@ def update_subnet_group(subnet_group, name, description, subnets):


def delete_subnet_group(name):

if module.check_mode:
return True

try:
client.delete_cache_subnet_group(
aws_retry=True,
Expand All @@ -206,7 +217,10 @@ def main():
global module
global client

module = AnsibleAWSModule(argument_spec=argument_spec)
module = AnsibleAWSModule(
argument_spec=argument_spec,
supports_check_mode=True,
)

state = module.params.get('state')
name = module.params.get('name').lower()
Expand Down
150 changes: 142 additions & 8 deletions tests/integration/targets/elasticache_subnet_group/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@
subnet_id_d: '{{ vpc_subnet_create.results[3].subnet.id }}'
# ============================================================

- name: Create Subnet Group - check_mode
elasticache_subnet_group:
state: present
name: '{{ group_name }}'
description: '{{ description_default }}'
subnets:
- '{{ subnet_id_a }}'
- '{{ subnet_id_b }}'
check_mode: True
register: create_group

- name: Check result - Create Subnet Group - check_mode
assert:
that:
- create_group is successful
- create_group is changed

- name: Create Subnet Group
elasticache_subnet_group:
state: present
Expand Down Expand Up @@ -88,6 +105,23 @@
- create_group.cache_subnet_group.arn.startswith('arn:')
- create_group.cache_subnet_group.arn.endswith(group_name)

- name: Create Subnet Group - idempotency - check_mode
elasticache_subnet_group:
state: present
name: '{{ group_name }}'
description: '{{ description_default }}'
subnets:
- '{{ subnet_id_a }}'
- '{{ subnet_id_b }}'
check_mode: True
register: create_group

- name: Check result - Create Subnet Group - idempotency - check_mode
assert:
that:
- create_group is successful
- create_group is not changed

- name: Create Subnet Group - idempotency
elasticache_subnet_group:
state: present
Expand Down Expand Up @@ -121,14 +155,33 @@

# ============================================================

- name: Update Subnet Group Description - check_mode
elasticache_subnet_group:
state: present
name: '{{ group_name }}'
description: '{{ description_updated }}'
## No longer mandatory
# subnets:
# - '{{ subnet_id_a }}'
# - '{{ subnet_id_b }}'
check_mode: True
register: update_description

- name: Check result - Update Subnet Group Description - check_mode
assert:
that:
- update_description is successful
- update_description is changed

- name: Update Subnet Group Description
elasticache_subnet_group:
state: present
name: '{{ group_name }}'
description: '{{ description_updated }}'
subnets:
- '{{ subnet_id_a }}'
- '{{ subnet_id_b }}'
## No longer mandatory
# subnets:
# - '{{ subnet_id_a }}'
# - '{{ subnet_id_b }}'
register: update_description

- name: Check result - Update Subnet Group Description
Expand All @@ -152,14 +205,33 @@
- update_description.cache_subnet_group.arn.startswith('arn:')
- update_description.cache_subnet_group.arn.endswith(group_name)

- name: Update Subnet Group Description - idempotency - check_mode
elasticache_subnet_group:
state: present
name: '{{ group_name }}'
description: '{{ description_updated }}'
## No longer mandatory
# subnets:
# - '{{ subnet_id_a }}'
# - '{{ subnet_id_b }}'
check_mode: True
register: update_description

- name: Check result - Update Subnet Group Description - idempotency - check_mode
assert:
that:
- update_description is successful
- update_description is not changed

- name: Update Subnet Group Description - idempotency
elasticache_subnet_group:
state: present
name: '{{ group_name }}'
description: '{{ description_updated }}'
subnets:
- '{{ subnet_id_a }}'
- '{{ subnet_id_b }}'
## No longer mandatory
# subnets:
# - '{{ subnet_id_a }}'
# - '{{ subnet_id_b }}'
register: update_description

- name: Check result - Update Subnet Group Description - idempotency
Expand All @@ -185,11 +257,30 @@

# ============================================================

- name: Update Subnet Group subnets - check_mode
elasticache_subnet_group:
state: present
name: '{{ group_name }}'
## No longer mandatory
# description: '{{ description_updated }}'
subnets:
- '{{ subnet_id_c }}'
- '{{ subnet_id_d }}'
check_mode: True
register: update_subnets

- name: Check result - Update Subnet Group subnets - check_mode
assert:
that:
- update_subnets is successful
- update_subnets is changed

- name: Update Subnet Group subnets
elasticache_subnet_group:
state: present
name: '{{ group_name }}'
description: '{{ description_updated }}'
## No longer mandatory
# description: '{{ description_updated }}'
subnets:
- '{{ subnet_id_c }}'
- '{{ subnet_id_d }}'
Expand All @@ -216,11 +307,30 @@
- update_subnets.cache_subnet_group.arn.startswith('arn:')
- update_subnets.cache_subnet_group.arn.endswith(group_name)

- name: Update Subnet Group subnets - idempotency - check_mode
elasticache_subnet_group:
state: present
name: '{{ group_name }}'
## No longer mandatory
# description: '{{ description_updated }}'
subnets:
- '{{ subnet_id_c }}'
- '{{ subnet_id_d }}'
check_mode: True
register: update_subnets

- name: Check result - Update Subnet Group subnets - idempotency - check_mode
assert:
that:
- update_subnets is successful
- update_subnets is not changed

- name: Update Subnet Group subnets - idempotency
elasticache_subnet_group:
state: present
name: '{{ group_name }}'
description: '{{ description_updated }}'
## No longer mandatory
# description: '{{ description_updated }}'
subnets:
- '{{ subnet_id_c }}'
- '{{ subnet_id_d }}'
Expand Down Expand Up @@ -249,6 +359,18 @@

# ============================================================

- name: Delete Subnet Group - check_mode
elasticache_subnet_group:
state: absent
name: '{{ group_name }}'
check_mode: True
register: delete_group

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

- name: Delete Subnet Group
elasticache_subnet_group:
state: absent
Expand All @@ -260,6 +382,18 @@
that:
- delete_group is changed

- name: Delete Subnet Group - idempotency - check_mode
elasticache_subnet_group:
state: absent
name: '{{ group_name }}'
check_mode: True
register: delete_group

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

- name: Delete Subnet Group - idempotency
elasticache_subnet_group:
state: absent
Expand Down

0 comments on commit e6804ce

Please sign in to comment.