-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cloudwatchevent_rule: Fix json input handling for input_template (#1883…
…) (#1969) [PR #1883/3b67513e backport][stable-6] cloudwatchevent_rule: Fix json input handling for input_template This is a backport of PR #1883 as merged into main (3b67513). SUMMARY Fixes #1842 This PR Moves _snakify() out of class CloudWatchEventRule https://github.com/ansible-collections/amazon.aws/pull/1883/files#diff-3a2f223edc4e34ea28b9859827a830844d92a8cd97f1300a2d16b1703a083bc8R213-R215 Fixes conditional in function _targets_to_put() to avoid wrong results due to _snakify() https://github.com/ansible-collections/amazon.aws/pull/1883/files#diff-3a2f223edc4e34ea28b9859827a830844d92a8cd97f1300a2d16b1703a083bc8R461-R463 Updates code to add quotes " to input_template only when the given input is not JSON to avoid quotes being added to provided JSON input https://github.com/ansible-collections/amazon.aws/pull/1883/files#diff-3a2f223edc4e34ea28b9859827a830844d92a8cd97f1300a2d16b1703a083bc8R452-R458 ISSUE TYPE Bugfix Pull Request COMPONENT NAME cloudwatchevent_rule ADDITIONAL INFORMATION Reviewed-by: Alina Buzachis
- Loading branch information
1 parent
871d37b
commit 512fe44
Showing
4 changed files
with
103 additions
and
9 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
...gelogs/fragments/1883-cloudwatchevent_rule-fix-json-input-handling-for-input_template.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
bugfixes: | ||
- cloudwatchevent_rule - Fix to avoid adding quotes to JSON input for provided input_template (https://github.com/ansible-collections/amazon.aws/pull/1883). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
tests/integration/targets/cloudwatchevent_rule/tasks/test_json_input_template.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
--- | ||
- name: Run tests for json input_template | ||
block: | ||
|
||
- name: Create SNS topic | ||
community.aws.sns_topic: | ||
name: TestSNSTopic-Json | ||
state: present | ||
display_name: Test SNS Topic | ||
register: sns_topic_output | ||
|
||
- name: Define JSON input_template | ||
ansible.builtin.set_fact: | ||
json_input_template: | | ||
{ | ||
"instance" : "<instance>", | ||
"state": "<state>" | ||
} | ||
- name: Create cloudwatch event rule with input transformer | ||
amazon.aws.cloudwatchevent_rule: | ||
name: "{{ input_transformer_event_name }}-Json" | ||
description: Event rule with input transformer configuration | ||
state: present | ||
event_pattern: '{"source":["aws.ec2"],"detail-type":["EC2 Instance State-change Notification"],"detail":{"state":["pending"]}}' | ||
targets: | ||
- id: "{{ sns_topic_output.sns_topic.name }}" | ||
arn: "{{ sns_topic_output.sns_topic.topic_arn }}" | ||
input_transformer: | ||
input_paths_map: | ||
instance: $.detail.instance-id | ||
state: $.detail.state | ||
input_template: "{{ json_input_template }}" | ||
register: event_rule_input_transformer_output | ||
|
||
- name: Assert that input transformer event rule was created | ||
ansible.builtin.assert: | ||
that: | ||
- event_rule_input_transformer_output.changed | ||
|
||
- name: Assert that event rule is created with a valid json value for input_template | ||
ansible.builtin.assert: | ||
that: | ||
- event_rule_input_transformer_output.targets[0].input_transformer.input_template | from_json | ||
|
||
- name: Create cloudwatch event rule with input transformer (idempotent) | ||
amazon.aws.cloudwatchevent_rule: | ||
name: "{{ input_transformer_event_name }}-Json" | ||
description: Event rule with input transformer configuration | ||
state: present | ||
event_pattern: '{"source":["aws.ec2"],"detail-type":["EC2 Instance State-change Notification"],"detail":{"state":["pending"]}}' | ||
targets: | ||
- id: "{{ sns_topic_output.sns_topic.name }}" | ||
arn: "{{ sns_topic_output.sns_topic.topic_arn }}" | ||
input_transformer: | ||
input_paths_map: | ||
instance: $.detail.instance-id | ||
state: $.detail.state | ||
input_template: "{{ json_input_template }}" | ||
register: event_rule_input_transformer_output | ||
|
||
always: | ||
- name: Assert that no changes were made to the rule | ||
ansible.builtin.assert: | ||
that: | ||
- event_rule_input_transformer_output is not changed | ||
|
||
- name: Delete input transformer CloudWatch event rules | ||
amazon.aws.cloudwatchevent_rule: | ||
name: "{{ input_transformer_event_name }}-Json" | ||
state: absent | ||
|
||
- name: Delete SNS topic | ||
community.aws.sns_topic: | ||
name: TestSNSTopic-Json | ||
state: absent |