Skip to content

Commit

Permalink
Merge pull request #1710 from ansible-collections/patchback/backports…
Browse files Browse the repository at this point in the history
…/stable-6/19b89f682227f8755322250c929355812dc37a2c/pr-1701

[PR #1701/19b89f68 backport][stable-6] Backup selection bugfix
  • Loading branch information
hakbailey authored Sep 1, 2023
2 parents 2c4c43b + b5a008a commit 47b0125
Show file tree
Hide file tree
Showing 3 changed files with 623 additions and 149 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/1701-backup-selection-bugfix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- backup_selection - ensures that updating an existing selection will add new ``Conditions`` if there previously were not any (https://github.com/ansible-collections/amazon.aws/pull/1701).
47 changes: 11 additions & 36 deletions plugins/modules/backup_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,45 +236,19 @@ def check_for_update(current_selection, backup_selection_data, iam_role_arn):
if current_selection[0].get("IamRoleArn", None) != iam_role_arn:
update_needed = True

fields_to_check = [
{
"field_name": "Resources",
"field_value_from_aws": json.dumps(current_selection[0].get("Resources", None), sort_keys=True),
"field_value": json.dumps(backup_selection_data.get("Resources", []), sort_keys=True),
},
{
"field_name": "ListOfTags",
"field_value_from_aws": json.dumps(current_selection[0].get("ListOfTags", None), sort_keys=True),
"field_value": json.dumps(backup_selection_data.get("ListOfTags", []), sort_keys=True),
},
{
"field_name": "NotResources",
"field_value_from_aws": json.dumps(current_selection[0].get("NotResources", None), sort_keys=True),
"field_value": json.dumps(backup_selection_data.get("NotResources", []), sort_keys=True),
},
{
"field_name": "Conditions",
"field_value_from_aws": json.dumps(current_selection[0].get("Conditions", None), sort_keys=True),
"field_value": json.dumps(backup_selection_data.get("Conditions", []), sort_keys=True),
},
]
for field_to_check in fields_to_check:
if field_to_check["field_value_from_aws"] != field_to_check["field_value"]:
if (
field_to_check["field_name"] != "Conditions"
and field_to_check["field_value_from_aws"] != "[]"
and field_to_check["field_value"] != "null"
):
# advanced settings to be updated
fields_to_check = ["Resources", "ListOfTags", "NotResources", "Conditions"]
for field_name in fields_to_check:
field_value_from_aws = json.dumps(current_selection[0].get(field_name, []), sort_keys=True)
new_field_value = json.dumps(backup_selection_data.get(field_name, []), sort_keys=True)
if new_field_value != field_value_from_aws:
if field_name != "Conditions":
update_needed = True
if (
field_to_check["field_name"] == "Conditions"
and field_to_check["field_value_from_aws"]
!= '{"StringEquals": [], "StringLike": [], "StringNotEquals": [], "StringNotLike": []}'
and field_to_check["field_value"] != "null"
elif not ( # Check that Conditions values are not both empty
field_value_from_aws
== '{"StringEquals": [], "StringLike": [], "StringNotEquals": [], "StringNotLike": []}' # Default AWS Conditions return value
and new_field_value == "[]"
):
update_needed = True

return update_needed


Expand Down Expand Up @@ -359,6 +333,7 @@ def main():
results = {"changed": False, "exists": False, "backup_selection": {}}

current_selection = get_selection_details(module, client, backup_plan_name, backup_selection_name)
results["current_selection"] = current_selection

if state == "present":
# build data specified by user
Expand Down
Loading

0 comments on commit 47b0125

Please sign in to comment.