Skip to content

Commit

Permalink
wafv2_ip_set - fix bugs with changing description (ansible-collection…
Browse files Browse the repository at this point in the history
…s#1211)

wafv2_ip_set - fix bugs with changing description

SUMMARY

updating just the description didn't update the changed state

ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
wafv2_ip_set
ADDITIONAL INFORMATION

Reviewed-by: Markus Bergholz <[email protected]>
  • Loading branch information
tremble committed Jun 4, 2022
1 parent 59f06ed commit 263c1cf
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 4 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/1211-wafv2_ip_set-description.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- wafv2_ip_set - fix bug where incorrect changed state was returned when only changing the description (https://github.com/ansible-collections/community.aws/pull/1211).
11 changes: 7 additions & 4 deletions plugins/modules/wafv2_ip_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,17 @@ def main():

if state == 'present':
if ip_set.get():
change, addresses = compare(ip_set.get(), addresses, purge_addresses, state)
if (change or ip_set.description() != description) and not check_mode:
ips_updated, addresses = compare(ip_set.get(), addresses, purge_addresses, state)
description_updated = bool(description) and ip_set.description() != description
change = ips_updated or description_updated
retval = ip_set.get()
if module.check_mode:
pass
elif ips_updated or description_updated:
retval = ip_set.update(
description=description,
addresses=addresses
)
else:
retval = ip_set.get()
else:
if not check_mode:
retval = ip_set.create(
Expand Down
131 changes: 131 additions & 0 deletions tests/integration/targets/wafv2_ip_set/tasks/description.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
- name: Tests relating to setting descriptions on wavf2_ip_sets
vars:
description_one: 'a Description - {{ resource_prefix }}'
description_two: 'Another_Description - {{ resource_prefix }}'
# Mandatory settings
module_defaults:
community.aws.wafv2_ip_set:
name: '{{ ip_set_name }}'
state: present
scope: REGIONAL
ip_address_version: IPV4
purge_addresses: no
addresses: []
community.aws.wafv2_ip_set_info:
name: '{{ ip_set_name }}'
scope: REGIONAL
block:

- name: test setting description wafv2_ip_set (check mode)
wafv2_ip_set:
description: '{{ description_one }}'
register: update_result
check_mode: yes
- name: assert that update succeeded
assert:
that:
- update_result is changed

- name: test setting description wafv2_ip_set
wafv2_ip_set:
description: '{{ description_one }}'
register: update_result
- name: assert that update succeeded
assert:
that:
- update_result is changed
- update_result.description == description_one

- name: test setting description wafv2_ip_set - idempotency (check mode)
wafv2_ip_set:
description: '{{ description_one }}'
register: update_result
check_mode: yes
- name: assert that update succeeded
assert:
that:
- update_result is not changed

- name: test setting description wafv2_ip_set - idempotency
wafv2_ip_set:
description: '{{ description_one }}'
register: update_result
- name: assert that update succeeded
assert:
that:
- update_result is not changed
- update_result.description == description_one

###

- name: test updating description on wafv2_ip_set (check mode)
wafv2_ip_set:
description: '{{ description_two }}'
register: update_result
check_mode: yes
- name: assert that update succeeded
assert:
that:
- update_result is changed

- name: test updating description on wafv2_ip_set
wafv2_ip_set:
description: '{{ description_two }}'
register: update_result
- name: assert that update succeeded
assert:
that:
- update_result is changed
- update_result.description == description_two

- name: test updating description on wafv2_ip_set - idempotency (check mode)
wafv2_ip_set:
description: '{{ description_two }}'
register: update_result
check_mode: yes
- name: assert that update succeeded
assert:
that:
- update_result is not changed

- name: test updating description on wafv2_ip_set - idempotency
wafv2_ip_set:
description: '{{ description_two }}'
register: update_result
- name: assert that update succeeded
assert:
that:
- update_result is not changed
- update_result.description == description_two

###

- name: test that wafv2_ip_set_info returns the description
wafv2_ip_set_info:
register: tag_info
- name: assert description present
assert:
that:
- tag_info.description == description_two

###

- name: test no description param wafv2_ip_set (check mode)
wafv2_ip_set: {}
register: update_result
check_mode: yes
- name: assert no change
assert:
that:
- update_result is not changed
- update_result.description == description_two


- name: test no description param wafv2_ip_set
wafv2_ip_set: {}
register: update_result
- name: assert no change
assert:
that:
- update_result is not changed
- update_result.description == description_two
2 changes: 2 additions & 0 deletions tests/integration/targets/wafv2_ip_set/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@
that:
- out.addresses | count == 1

- include_tasks: 'description.yml'

- name: delete ip set
wafv2_ip_set:
name: "{{ ip_set_name }}"
Expand Down

0 comments on commit 263c1cf

Please sign in to comment.