diff --git a/changelogs/fragments/802-update-s3-module_util-validate_bucket_name-to-accept-3-character-bucket-name.yml b/changelogs/fragments/802-update-s3-module_util-validate_bucket_name-to-accept-3-character-bucket-name.yml new file mode 100644 index 00000000000..19dddbdad87 --- /dev/null +++ b/changelogs/fragments/802-update-s3-module_util-validate_bucket_name-to-accept-3-character-bucket-name.yml @@ -0,0 +1,2 @@ +bugfixes: + - module.utils.s3 - Update validate_bucket_name minimum length to 3 (https://github.com/ansible-collections/amazon.aws/pull/802). diff --git a/plugins/module_utils/s3.py b/plugins/module_utils/s3.py index 177e9cca0c6..c13c91f25b1 100644 --- a/plugins/module_utils/s3.py +++ b/plugins/module_utils/s3.py @@ -88,8 +88,8 @@ def calculate_etag_content(module, content, etag, s3, bucket, obj, version=None) def validate_bucket_name(module, name): # See: https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html - if len(name) < 4: - module.fail_json(msg='the S3 bucket name is too short') + if len(name) < 3: + module.fail_json(msg='the length of an S3 bucket must be at least 3 characters') if len(name) > 63: module.fail_json(msg='the length of an S3 bucket cannot exceed 63 characters') diff --git a/tests/unit/module_utils/test_s3.py b/tests/unit/module_utils/test_s3.py index b470f613d4d..b078f718db2 100644 --- a/tests/unit/module_utils/test_s3.py +++ b/tests/unit/module_utils/test_s3.py @@ -27,6 +27,8 @@ def test_validate_bucket_name(): assert not module.fail_json.called assert s3.validate_bucket_name(module, "my.example.s3.bucket") is True assert not module.fail_json.called + assert s3.validate_bucket_name(module, "doc") is True + assert not module.fail_json.called module.fail_json.reset_mock() s3.validate_bucket_name(module, "doc_example_bucket") @@ -38,3 +40,5 @@ def test_validate_bucket_name(): module.fail_json.reset_mock() s3.validate_bucket_name(module, "doc-example-bucket-") assert module.fail_json.called + s3.validate_bucket_name(module, "my") + assert module.fail_json.called