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

wafv2_web_acl: prevent exception when element is not a dict #962

Merged
merged 5 commits into from
Mar 15, 2022
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/962-fix-waf-list-conditions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- wafv2_web_acl - fix exception when a rule contains lists values (https://github.com/ansible-collections/community.aws/pull/962).
3 changes: 3 additions & 0 deletions plugins/module_utils/wafv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def wafv2_list_rule_groups(wafv2, scope, fail_json_aws, nextmarker=None):


def wafv2_snake_dict_to_camel_dict(a):
if not isinstance(a, dict):
return a

retval = {}
for item in a.keys():
if isinstance(a.get(item), dict):
Expand Down
45 changes: 45 additions & 0 deletions tests/integration/targets/wafv2/tasks/test_webacl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,48 @@
assert:
that:
- out is not changed

- name: test geo match statement
wafv2_web_acl:
name: "{{ web_acl_name }}"
state: present
description: hallo eins drei
scope: REGIONAL
default_action: Allow
sampled_requests: no
cloudwatch_metrics: yes
metric_name: blub
purge_rules: yes
rules:
- name: block-germany
priority: 1
action:
block: {}
visibility_config:
sampled_requests_enabled: yes
cloud_watch_metrics_enabled: yes
metric_name: block-germany
statement:
geo_match_statement:
country_codes:
- DE
tags:
A: B
C: D
register: out

- name: verify change
assert:
that:
- out is changed

- name: re-read webacl
wafv2_web_acl_info:
name: "{{ web_acl_name }}"
scope: REGIONAL
register: out

- name: verify geo match statement
assert:
that:
- out.rules[0].statement.geo_match_statement.country_codes[0] == 'DE'