Skip to content

Commit

Permalink
Merge pull request #25724 from mattbork/b-aws_s3_bucket-regional_doma…
Browse files Browse the repository at this point in the history
…in_name_fix

Fix bucket_regional_domain_name for us-east-1 region
  • Loading branch information
gdavison authored May 24, 2023
2 parents fbcbf06 + 367b8e4 commit f6a0967
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .changelog/25724.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_s3_bucket: Fix bucket_regional_domain_name not including region for buckets in us-east-1
```
5 changes: 4 additions & 1 deletion internal/service/s3/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,10 @@ func BucketRegionalDomainName(bucket string, region string) (string, error) {
if region == "" {
return fmt.Sprintf("%s.s3.amazonaws.com", bucket), nil //lintignore:AWSR001
}
endpoint, err := endpoints.DefaultResolver().EndpointFor(s3.EndpointsID, region)
endpoint, err := endpoints.DefaultResolver().EndpointFor(s3.EndpointsID, region, func(o *endpoints.Options) {
// By default, EndpointFor uses the legacy endpoint for S3 in the us-east-1 region
o.S3UsEast1RegionalEndpoint = endpoints.RegionalS3UsEast1Endpoint
})
if err != nil {
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/s3/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2345,7 +2345,7 @@ func TestBucketRegionalDomainName(t *testing.T) {
{
Region: endpoints.UsEast1RegionID,
ExpectedErrCount: 0,
ExpectedOutput: bucket + ".s3.amazonaws.com",
ExpectedOutput: bucket + fmt.Sprintf(".s3.%s.%s", endpoints.UsEast1RegionID, acctest.PartitionDNSSuffix()),
},
{
Region: endpoints.UsWest2RegionID,
Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/s3_bucket.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ In addition to all arguments above, the following attributes are exported:
* `id` - Name of the bucket.
* `arn` - ARN of the bucket. Will be of format `arn:aws:s3:::bucketname`.
* `bucket_domain_name` - Bucket domain name. Will be of format `bucketname.s3.amazonaws.com`.
* `bucket_regional_domain_name` - The bucket region-specific domain name. The bucket domain name including the region name, please refer [here](https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region) for format. Note: The AWS CloudFront allows specifying S3 region-specific endpoint when creating S3 origin, it will prevent [redirect issues](https://forums.aws.amazon.com/thread.jspa?threadID=216814) from CloudFront to S3 Origin URL.
* `bucket_regional_domain_name` - The bucket region-specific domain name. The bucket domain name including the region name. Please refer to the [S3 endpoints reference](https://docs.aws.amazon.com/general/latest/gr/s3.html#s3_region) for format. Note: AWS CloudFront allows specifying an S3 region-specific endpoint when creating an S3 origin. This will prevent redirect issues from CloudFront to the S3 Origin URL. For more information, see the [Virtual Hosted-Style Requests for Other Regions](https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html#deprecated-global-endpoint) section in the AWS S3 User Guide.
* `hosted_zone_id` - The [Route 53 Hosted Zone ID](https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_website_region_endpoints) for this bucket's region.
* `region` - AWS region this bucket resides in.
* `website_endpoint` - Website endpoint, if the bucket is configured with a website. If not, this will be an empty string.
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/s3_bucket.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ In addition to all arguments above, the following attributes are exported:
* `id` - Name of the bucket.
* `arn` - ARN of the bucket. Will be of format `arn:aws:s3:::bucketname`.
* `bucket_domain_name` - Bucket domain name. Will be of format `bucketname.s3.amazonaws.com`.
* `bucket_regional_domain_name` - Bucket region-specific domain name. The bucket domain name including the region name, please refer [here](https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region) for format. Note: The AWS CloudFront allows specifying S3 region-specific endpoint when creating S3 origin, it will prevent [redirect issues](https://forums.aws.amazon.com/thread.jspa?threadID=216814) from CloudFront to S3 Origin URL.
* `bucket_regional_domain_name` - The bucket region-specific domain name. The bucket domain name including the region name. Please refer to the [S3 endpoints reference](https://docs.aws.amazon.com/general/latest/gr/s3.html#s3_region) for format. Note: AWS CloudFront allows specifying an S3 region-specific endpoint when creating an S3 origin. This will prevent redirect issues from CloudFront to the S3 Origin URL. For more information, see the [Virtual Hosted-Style Requests for Other Regions](https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html#deprecated-global-endpoint) section in the AWS S3 User Guide.
* `hosted_zone_id` - [Route 53 Hosted Zone ID](https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_website_region_endpoints) for this bucket's region.
* `region` - AWS region this bucket resides in.
* `tags_all` - Map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block).
Expand Down

0 comments on commit f6a0967

Please sign in to comment.