Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrected Frankfurt S3 Website Endpoint #2259

Merged
merged 1 commit into from
Jun 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
}