Skip to content

Commit

Permalink
Ensure modules are idempotent
Browse files Browse the repository at this point in the history
Signed-off-by: Alina Buzachis <[email protected]>
  • Loading branch information
alinabuzachis committed Oct 9, 2024
1 parent b9e2717 commit b770828
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 10 deletions.
4 changes: 3 additions & 1 deletion plugins/module_utils/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ def fields_could_be_same(old_field: Any, new_field: Any) -> bool:
return True # all sub-fields are either equal or could be equal
if old_field == Controller.ENCRYPTED_STRING:
return True

return bool(new_field == old_field)

def objects_could_be_different(
Expand All @@ -256,13 +257,14 @@ def objects_could_be_different(
for field in field_set:
new_field = new.get(field, None)
old_field = old.get(field, None)

if old_field != new_field:
if self.update_secrets or (
not self.fields_could_be_same(old_field, new_field)
):
return True # Something doesn't match, or something
# might not match
elif self.has_encrypted_values(new_field) or field not in new:
elif self.has_encrypted_values(new_field):
if self.update_secrets or (
not self.fields_could_be_same(old_field, new_field)
):
Expand Down
3 changes: 0 additions & 3 deletions tests/integration/targets/credential/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,10 @@
organization_name: Default
register: _result

# [WARNING]: The field inputs of unknown 3 has encrypted data and may inaccurately report task is changed.
- name: Check credential is not created again
assert:
that:
- not _result.changed
ignore_errors: true

- name: Get info about a credential
ansible.eda.credential_info:
Expand Down Expand Up @@ -121,7 +119,6 @@
organization_name: Default
register: _result

# [WARNING]: The field inputs of unknown 3 has encrypted data and may inaccurately report task is changed.
- name: Check credential is not updated again
assert:
that:
Expand Down
6 changes: 0 additions & 6 deletions tests/integration/targets/event_stream/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,10 @@
event_stream_type: "basic"
register: _result

# [WARNING]: The field eda_credential_id of unknown 2 has encrypted data and may
# inaccurately report task is changed.
- name: Check event stream is not created again
assert:
that:
- not _result.changed
ignore_errors: true

- name: Get info about an event stream
ansible.eda.event_stream_info:
Expand Down Expand Up @@ -115,13 +112,10 @@
event_stream_type: "basic"
register: _result

# [WARNING]: The field eda_credential_id of unknown 5 has encrypted data and may
# inaccurately report task is changed.
- name: Check event stream is not updated again
assert:
that:
- not _result.changed
ignore_errors: true

- name: Get info about event stream
ansible.eda.event_stream_info:
Expand Down

0 comments on commit b770828

Please sign in to comment.