diff --git a/builtin/providers/aws/resource_aws_s3_bucket.go b/builtin/providers/aws/resource_aws_s3_bucket.go index ddeab6a19f..36d843fdce 100644 --- a/builtin/providers/aws/resource_aws_s3_bucket.go +++ b/builtin/providers/aws/resource_aws_s3_bucket.go @@ -260,13 +260,15 @@ func websiteEndpoint(s3conn *s3.S3, d *schema.ResourceData) (string, error) { region = *location.LocationConstraint } + return WebsiteEndpointUrl(bucket, region), nil +} + +func WebsiteEndpointUrl(bucket string, region string) string { // Default to us-east-1 if the bucket doesn't have a region: // http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketGETlocation.html if region == "" { region = "us-east-1" } - endpoint := fmt.Sprintf("%s.s3-website-%s.amazonaws.com", bucket, region) - - return endpoint, nil + 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 new file mode 100644 index 0000000000..38b11d329b --- /dev/null +++ b/builtin/providers/aws/website_endpoint_url_test.go @@ -0,0 +1,17 @@ +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) + } +} + +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) + } +}