From 52a21f3fb03f6c7561c1db23039c5c2d18f9457c Mon Sep 17 00:00:00 2001 From: Alexander Ekdahl Date: Sun, 7 Jun 2015 11:39:18 +0200 Subject: [PATCH] Corrected Frankfurt S3 Website Endpoint fixes #2258 --- .../providers/aws/resource_aws_s3_bucket.go | 7 +++++ .../aws/website_endpoint_url_test.go | 29 +++++++++++++------ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/builtin/providers/aws/resource_aws_s3_bucket.go b/builtin/providers/aws/resource_aws_s3_bucket.go index 332c99569..93bf24390 100644 --- a/builtin/providers/aws/resource_aws_s3_bucket.go +++ b/builtin/providers/aws/resource_aws_s3_bucket.go @@ -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) } diff --git a/builtin/providers/aws/website_endpoint_url_test.go b/builtin/providers/aws/website_endpoint_url_test.go index 38b11d329..2f4ce5249 100644 --- a/builtin/providers/aws/website_endpoint_url_test.go +++ b/builtin/providers/aws/website_endpoint_url_test.go @@ -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) + } } }