From dfea08e463c9d90c8e5416b2709e34c6ee2f7a81 Mon Sep 17 00:00:00 2001 From: evohnave Date: Thu, 11 May 2023 12:18:59 -0400 Subject: [PATCH] s3_bucket: fix VersionId==null when s3 object not versioned (#1538) s3_bucket: fix VersionId==null when s3 object not versioned SUMMARY Boto3 1.26.129 (possibly earlier) returns "VersionId": "null" from s3_client.list_object_versions() when s3 objects are not versioned. Previously, "VersionId" was None when an s3 object was not versioned. This change broke s3_bucket.destroy_bucket() because the the VersionId was no longer popped (line 1166) when the s3 object was not versioned, and the subsequent attempts to delete the s3 object failed as the "VersionId" was absolutely not "null". Adding in `or fk.get("VersionId")=="null" will catch this new value for non-versioned s3 objects while allowing backwards compatibility with previous versions that return None for "VersionId". Fixes #1533 s3_bucket.destroy_bucket fails to delete unversioned items ISSUE TYPE Bugfix Pull Request COMPONENT NAME s3_bucket.py ADDITIONAL INFORMATION Ensure that there is an s3 bucket with objects in it name: Remove buckets s3_bucket: name: "my_bucket_with_objects_with_no_versioning" state: absent force: yes Reviewed-by: Mark Chappell (cherry picked from commit 94bb14c207215f83d8c5c6939ed177be30f5f8df) --- changelogs/fragments/1538-s3-null.yml | 2 ++ plugins/modules/s3_bucket.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/1538-s3-null.yml diff --git a/changelogs/fragments/1538-s3-null.yml b/changelogs/fragments/1538-s3-null.yml new file mode 100644 index 00000000000..7c2ccfa6bd8 --- /dev/null +++ b/changelogs/fragments/1538-s3-null.yml @@ -0,0 +1,2 @@ +bugfixes: +- s3_bucket - fixes issue when deleting a bucket with unversioned objects (https://github.com/ansible-collections/amazon.aws/issues/1533). diff --git a/plugins/modules/s3_bucket.py b/plugins/modules/s3_bucket.py index c0a78e39a63..d242acc8399 100644 --- a/plugins/modules/s3_bucket.py +++ b/plugins/modules/s3_bucket.py @@ -1163,7 +1163,7 @@ def destroy_bucket(s3_client, module): # unversioned objects are deleted using `DeleteObject` # rather than `DeleteObjectVersion`, improving backwards # compatibility with older IAM policies. - if not fk.get("VersionId"): + if not fk.get("VersionId") or fk.get("VersionId") == "null": fk.pop("VersionId") if formatted_keys: