Skip to content

Commit

Permalink
s3_bucket - do not use default region as location constraint when cre…
Browse files Browse the repository at this point in the history
…ating bucket on ceph cluster (#2457)

SUMMARY

Closes #2420
Do not use the default region as a location constraint when creating a bucket.

ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

s3_bucket

Reviewed-by: Mark Chappell
Reviewed-by: Alina Buzachis
(cherry picked from commit 6bbf22f)
  • Loading branch information
abikouo authored and patchback[bot] committed Jan 14, 2025
1 parent a60cf3c commit 917847e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- s3_bucket - Do not use default region as location constraint when creating bucket on ceph cluster (https://github.com/ansible-collections/amazon.aws/issues/2420).
6 changes: 6 additions & 0 deletions plugins/module_utils/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,9 @@ def _list_objects_v2(client, **params):
def list_bucket_object_keys(client, bucket, prefix=None, max_keys=None, start_after=None):
response = _list_objects_v2(client, Bucket=bucket, Prefix=prefix, StartAfter=start_after, MaxKeys=max_keys)
return [c["Key"] for c in response.get("Contents", [])]


def get_s3_bucket_location(module):
if module.params.get("ceph") is True:
return module.params.get("region")
return module.region or "us-east-1"
5 changes: 2 additions & 3 deletions plugins/modules/s3_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.policy import compare_policies
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.s3 import get_s3_bucket_location
from ansible_collections.amazon.aws.plugins.module_utils.s3 import list_bucket_inventory_configurations
from ansible_collections.amazon.aws.plugins.module_utils.s3 import s3_extra_params
from ansible_collections.amazon.aws.plugins.module_utils.s3 import validate_bucket_name
Expand Down Expand Up @@ -1232,9 +1233,7 @@ def create_or_update_bucket(s3_client, module: AnsibleAWSModule):
"""
name = module.params.get("name")
object_lock_enabled = module.params.get("object_lock_enabled")
# default to US Standard region,
# note: module.region will also try to pull a default out of the boto3 configs.
location = module.region or "us-east-1"
location = get_s3_bucket_location(module)

changed = False
result = {}
Expand Down

0 comments on commit 917847e

Please sign in to comment.