Skip to content

Commit

Permalink
Merge pull request #2259 from AlexanderEkdahl/s3_website_endpoint_fix
Browse files Browse the repository at this point in the history
Corrected Frankfurt S3 Website Endpoint
  • Loading branch information
phinze committed Jun 7, 2015
2 parents c852ac5 + 52a21f3 commit c4bb975
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
7 changes: 7 additions & 0 deletions builtin/providers/aws/resource_aws_s3_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,13 @@ func websiteEndpoint(s3conn *s3.S3, d *schema.ResourceData) (string, error) {

func WebsiteEndpointUrl(bucket string, region string) string {
region = normalizeRegion(region)

// Frankfurt(and probably future) regions uses different syntax for website endpoints
// http://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteEndpoints.html
if region == "eu-central-1" {
return fmt.Sprintf("%s.s3-website.%s.amazonaws.com", bucket, region)
}

return fmt.Sprintf("%s.s3-website-%s.amazonaws.com", bucket, region)
}

Expand Down
29 changes: 20 additions & 9 deletions builtin/providers/aws/website_endpoint_url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,27 @@ package aws

import "testing"

func TestWebsiteEndpointUrl_withoutRegion(t *testing.T) {
u := WebsiteEndpointUrl("buck.et", "")
if u != "buck.et.s3-website-us-east-1.amazonaws.com" {
t.Fatalf("bad: %s", u)
}
// http://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteEndpoints.html
var websiteEndpoints = []struct {
in string
out string
}{
{"", "bucket-name.s3-website-us-east-1.amazonaws.com"},
{"us-west-2", "bucket-name.s3-website-us-west-2.amazonaws.com"},
{"us-west-1", "bucket-name.s3-website-us-west-1.amazonaws.com"},
{"eu-west-1", "bucket-name.s3-website-eu-west-1.amazonaws.com"},
{"eu-central-1", "bucket-name.s3-website.eu-central-1.amazonaws.com"},
{"ap-southeast-1", "bucket-name.s3-website-ap-southeast-1.amazonaws.com"},
{"ap-northeast-1", "bucket-name.s3-website-ap-northeast-1.amazonaws.com"},
{"ap-southeast-2", "bucket-name.s3-website-ap-southeast-2.amazonaws.com"},
{"sa-east-1", "bucket-name.s3-website-sa-east-1.amazonaws.com"},
}

func TestWebsiteEndpointUrl_withRegion(t *testing.T) {
u := WebsiteEndpointUrl("buck.et", "us-west-1")
if u != "buck.et.s3-website-us-west-1.amazonaws.com" {
t.Fatalf("bad: %s", u)
func TestWebsiteEndpointUrl(t *testing.T) {
for _, tt := range websiteEndpoints {
s := WebsiteEndpointUrl("bucket-name", tt.in)
if s != tt.out {
t.Errorf("WebsiteEndpointUrl(\"bucket-name\", %q) => %q, want %q", tt.in, s, tt.out)
}
}
}

0 comments on commit c4bb975

Please sign in to comment.