Skip to content

Commit

Permalink
wafv2_ip_set - fix bugs with changing description (#1211)
Browse files Browse the repository at this point in the history
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 authored Jun 4, 2022
1 parent 6a2793a commit b6ed8d5
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 5 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).
14 changes: 9 additions & 5 deletions plugins/modules/wafv2_ip_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,15 +314,19 @@ def main():

if ip_set.get():
tags_updated = ensure_wafv2_tags(wafv2, ip_set.arn, tags, purge_tags, module.fail_json_aws, module.check_mode)
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 or tags_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()
change |= tags_updated
elif tags_updated:
retval, id, locktoken, arn = ip_set.get_set()
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
1 change: 1 addition & 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,7 @@
- out.addresses | count == 1

- include_tasks: 'tagging.yml'
- include_tasks: 'description.yml'

- name: delete ip set
wafv2_ip_set:
Expand Down

0 comments on commit b6ed8d5

Please sign in to comment.