Skip to content

Commit

Permalink
Merge pull request #9444 from antonio-osorio/fix_china_website_endpoi…
Browse files Browse the repository at this point in the history
…nt_url

Fixes website_endpoint and website_domain attributes in Chinese regions
  • Loading branch information
bflad authored Jul 24, 2019
2 parents c820b93 + b5042c0 commit 200e193
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions aws/resource_aws_s3_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -1589,11 +1589,15 @@ func WebsiteEndpoint(bucket string, region string) *S3Website {
func WebsiteDomainUrl(region string) string {
region = normalizeRegion(region)

// New regions uses different syntax for website endpoints
// http://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteEndpoints.html
// Different regions have different syntax for website endpoints
// https://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteEndpoints.html
// https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_website_region_endpoints
if isOldRegion(region) {
return fmt.Sprintf("s3-website-%s.amazonaws.com", region)
}
if partition, ok := endpoints.PartitionForRegion(endpoints.DefaultPartitions(), region); ok && partition.ID() == endpoints.AwsCnPartitionID {
return fmt.Sprintf("s3-website.%s.amazonaws.com.cn", region)
}
return fmt.Sprintf("s3-website.%s.amazonaws.com", region)
}

Expand Down
2 changes: 2 additions & 0 deletions aws/website_endpoint_url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ var websiteEndpoints = []struct {
{"ap-southeast-2", "bucket-name.s3-website-ap-southeast-2.amazonaws.com"},
{"ap-northeast-2", "bucket-name.s3-website.ap-northeast-2.amazonaws.com"},
{"sa-east-1", "bucket-name.s3-website-sa-east-1.amazonaws.com"},
{"cn-northwest-1", "bucket-name.s3-website.cn-northwest-1.amazonaws.com.cn"},
{"cn-north-1", "bucket-name.s3-website.cn-north-1.amazonaws.com.cn"},
}

func TestWebsiteEndpointUrl(t *testing.T) {
Expand Down

0 comments on commit 200e193

Please sign in to comment.