Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable-3] wafv2_ip_set - fix bugs with changing description #1214

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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