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

cloudwatchevent_rule should return false when there is no change done to the rule #1589

Merged
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
fd16836
Changes to the _target_to_put in cloudwatchevent_rule
taehopark32 Jun 1, 2023
d3887d1
Changes made to method (_target_to_put) in cloudwatcheevent_ruler
taehopark32 Jun 1, 2023
d940d0a
Changes to method (_target_to_put) in cloudwatchevent_ruler
taehopark32 Jun 1, 2023
b974349
Changes to method (_target_to_put) in cloudwatchevent_ruler
taehopark32 Jun 1, 2023
c950f50
test
taehopark32 Jun 1, 2023
1a64051
Update README.md
taehopark32 Jun 1, 2023
0ef87b2
deleted the keys
taehopark32 Jun 1, 2023
98a405a
added fragmens and tests
taehopark32 Jun 1, 2023
2e19dd4
changes to the target (for accurate discription) and cloudwatchevent_…
taehopark32 Jun 1, 2023
3bc5d03
change to the test tasks in cloudwatchevent_rule for Assert that no c…
taehopark32 Jun 1, 2023
5b9f256
changes to the Assert that no changes were made to the rule
taehopark32 Jun 1, 2023
5c86663
Changes to the test
taehopark32 Jun 2, 2023
15a646b
Changes to the idempotent
taehopark32 Jun 5, 2023
bc356b9
Added quotes
taehopark32 Jun 5, 2023
d3a833d
removed import q
taehopark32 Jun 5, 2023
58948b9
added another condition where input_transformer could be None
taehopark32 Jun 5, 2023
38583bd
remove a file
taehopark32 Jun 5, 2023
44c361e
fixed the quote problem
taehopark32 Jun 6, 2023
0786e93
changes to the suggestion
taehopark32 Jun 6, 2023
c8ac229
fix trailing space in integration cloudwatchevent_rule
taehopark32 Jun 6, 2023
807ad1e
used tox to structure
taehopark32 Jun 6, 2023
0d56a8c
changed description to be more user friendly
taehopark32 Jun 6, 2023
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
3 changes: 3 additions & 0 deletions changelogs/fragments/1589-return_false_when_no_change..yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- cloudwatchevent_rule - add scrub none inside the _targets_to_put method (https://github.com/ansible-collections/amazon.aws/pull/1589)."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changelog should describe what the end user needs to know, functionaly, about the change, rather than the implementation details of the code. Something like
"Fixes changed status to report False when no change has been made. The module had incorrectly always reported a change."
But make sure it describes whatever scenario the wrong change status would have occurred for, if it wasn't always.

12 changes: 12 additions & 0 deletions plugins/modules/cloudwatchevent_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,18 @@ def _rule_matches_aws(self):
def _targets_to_put(self):
"""Returns a list of targets that need to be updated or added remotely"""
remote_targets = self.rule.list_targets()

# keys with none values must be scrubbed off of self.targets
temp = []
for t in self.targets:
if t["input_transformer"] is not None and t["input_transformer"]["input_template"] is not None:
# The remote_targets contain quotes, so add
# quotes to temp
val = t["input_transformer"]["input_template"]
t["input_transformer"]["input_template"] = '"' + val + '"'
temp.append(scrub_none_parameters(t))
self.targets = temp

return [t for t in self.targets if t not in remote_targets]

def _remote_target_ids_to_remove(self):
Expand Down
21 changes: 21 additions & 0 deletions tests/integration/targets/cloudwatchevent_rule/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,27 @@
that:
- event_rule_input_transformer_output.changed

- name: Create cloudwatch event rule with input transformer (idempotent)
cloudwatchevent_rule:
name: "{{ input_transformer_event_name }}"
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: "<instance> is in state <state>"
register: event_rule_input_transformer_output

- name: Assert that no changes were made to the rule
assert:
that:
- event_rule_input_transformer_output is not changed

- name: Create cloudwatch event rule with inputs
cloudwatchevent_rule:
name: "{{ input_event_name }}"
Expand Down