resource/aws_s3_bucket: fix CreateBucket LocationConstraint for S3-compatible endpoints - #49890
Open
kayrus wants to merge 1 commit into
Open
resource/aws_s3_bucket: fix CreateBucket LocationConstraint for S3-compatible endpoints#49890kayrus wants to merge 1 commit into
kayrus wants to merge 1 commit into
Conversation
Contributor
Community GuidelinesThis comment is added to every new Pull Request to provide quick reference to how the Terraform AWS Provider is maintained. Please review the information below, and thank you for contributing to the community that keeps the provider thriving! 🚀 Voting for Prioritization
Pull Request Authors
|
kayrus
force-pushed
the
fix-custom-constraints
branch
from
September 8, 2026 13:19
52a94cf to
020b772
Compare
…mpatible endpoints When a custom S3 endpoint is configured with a non-standard region string (e.g. Ceph RGW or MinIO region names such as ":region-ha-premium"), the provider substitutes the configured region with a compliant dummy value (us-east-1) so the AWS SDK v2 region validation passes, preserving the original region for request signing. The CreateBucket request derived its LocationConstraint from the (now substituted) effective region. Because that value equals us-east-1, the LocationConstraint was omitted and an empty CreateBucketConfiguration was sent, which S3-compatible backends reject with 400 InvalidArgument. Prefer the preserved original region for the LocationConstraint so the create request matches the configured region, restoring the behavior of provider v5.x. Native AWS is unaffected: the original region is only set for non-AWS regions behind a custom S3 endpoint, so us-east-1 continues to send no LocationConstraint. Closes hashicorp#46517
kayrus
force-pushed
the
fix-custom-constraints
branch
from
September 9, 2026 10:09
020b772 to
535df5e
Compare
Author
|
@gdavison @jar-b @ewbankkit @YakDriver could you please review this PR? |
Author
|
cc @justinretzolk I'd appreciate it if you could also have a look at this PR when convenient |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rollback Plan
If a change needs to be reverted, we will publish an updated version of the library.
Changes to Security Controls
This change only affects the
LocationConstraintvalue sent in the S3CreateBucketrequest body when a custom S3 endpoint is configured with a non-standard region string. It does not alter access controls, encryption, or logging. Request signing behavior is unchanged.Description
When a custom S3 endpoint is configured (
endpoints { s3 = ... }) together with a non-standard region string — for example the region names used by Ceph RGW or MinIO such as:region-ha-premiumorceph-objectstore-region1:region-ha-premium— the provider substitutes the configured region with a compliant dummy value (us-east-1) so the AWS SDK for Go v2's strict region validation passes, while preserving the original region for request signing.The problem:
resourceBucketCreatederived theCreateBucketLocationConstraintfrom the (now substituted) effective region. Since that value isus-east-1— where AWS requires that noLocationConstraintbe sent — the constraint was omitted and an empty<CreateBucketConfiguration></CreateBucketConfiguration>was sent. S3-compatible backends reject this with400 InvalidArgument, so bucket creation fails. Provider v5.x sent the configured region verbatim and worked.This PR prefers the preserved original region for the
LocationConstraintso the create request again matches the configured region:internal/conns/awsclient.go: adds an exportedS3OriginalRegion(ctx)accessor for the region preserved during the S3-compatible substitution.internal/service/s3/bucket.go: extracts theLocationConstraintderivation into a pure, exported helperBucketLocationConstraint(region, originalRegion)and uses it inresourceBucketCreate. It prefers the original region when set, and continues to send no constraint forus-east-1.Native AWS is unaffected:
S3OriginalRegionis only populated for a non-AWS region behind a custom S3 endpoint, so on AWS the effective region is used andus-east-1continues to send noLocationConstraint. Any non-standard region string is passed through verbatim; the equivalence of the prefixed and bare Ceph forms is enforced server-side by Ceph, not by the provider.Verified against a Ceph RGW gateway:
terraform applynow sends<LocationConstraint>:region-ha-premium</LocationConstraint>and the bucket is created (HTTP 200), matching provider v5.x behavior.CreateBucketrequest bodyConfig used (Ceph RGW endpoint, non-standard region
:region-ha-premium):Before (v6.63.0, broken) — the substituted
us-east-1region caused theLocationConstraintto be dropped, sending an empty configuration that Ceph rejects with400 InvalidArgument:After (this PR / matches v5.100.0) — the preserved original region is sent as the
LocationConstraintand Ceph accepts it:Relations
Closes #46517
References
CreateBucketLocationConstraintreference: https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateBucket.html#AmazonS3-CreateBucket-request-LocationConstraintCreateBucketConfigurationhandling: [Bug]: aws_s3_bucket CreateBucket fails with MalformedXML on OVH S3-compatible API (provider 6.35+) #47061Output from Acceptance Testing