From a9906e71fc34994971e855c34cad53bbcbff7a7c Mon Sep 17 00:00:00 2001 From: Taeho Park <113317744+taehopark32@users.noreply.github.com> Date: Tue, 4 Jul 2023 05:08:34 -0400 Subject: [PATCH] cloudwatchevent_rule should return false when there is no change done to the rule (#1589) cloudwatchevent_rule should return false when there is no change done to the rule SUMMARY Fixes #1080 ISSUE TYPE Bugfix Pull Request COMPONENT NAME plugins/modules/cloudwatchevent_rule.py ADDITIONAL INFORMATION Reviewed-by: GomathiselviS Reviewed-by: Mark Chappell Reviewed-by: Jill R Reviewed-by: Alina Buzachis (cherry picked from commit 614b792be81a8a64c8c955093c853733ca1f57c3) --- .../1589-return_false_when_no_change..yml | 3 +++ plugins/modules/cloudwatchevent_rule.py | 12 +++++++++++ .../cloudwatchevent_rule/tasks/main.yml | 21 +++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 changelogs/fragments/1589-return_false_when_no_change..yml diff --git a/changelogs/fragments/1589-return_false_when_no_change..yml b/changelogs/fragments/1589-return_false_when_no_change..yml new file mode 100644 index 0000000000..5b5367c5f6 --- /dev/null +++ b/changelogs/fragments/1589-return_false_when_no_change..yml @@ -0,0 +1,3 @@ +--- +bugfixes: +- Fixes changed status to report False when no change has been made. The module had incorrectly always reported a change. (https://github.com/ansible-collections/amazon.aws/pull/1589) \ No newline at end of file diff --git a/plugins/modules/cloudwatchevent_rule.py b/plugins/modules/cloudwatchevent_rule.py index 828e75533b..8f6f1fe573 100644 --- a/plugins/modules/cloudwatchevent_rule.py +++ b/plugins/modules/cloudwatchevent_rule.py @@ -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): diff --git a/tests/integration/targets/cloudwatchevent_rule/tasks/main.yml b/tests/integration/targets/cloudwatchevent_rule/tasks/main.yml index 0047831a7b..9243742d78 100644 --- a/tests/integration/targets/cloudwatchevent_rule/tasks/main.yml +++ b/tests/integration/targets/cloudwatchevent_rule/tasks/main.yml @@ -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: " is in 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 }}"