diff --git a/builtin/providers/aws/hosted_zones.go b/builtin/providers/aws/hosted_zones.go index e119f9d9e21b..936148dbe532 100644 --- a/builtin/providers/aws/hosted_zones.go +++ b/builtin/providers/aws/hosted_zones.go @@ -15,9 +15,5 @@ var hostedZoneIDsMap = map[string]string{ } func HostedZoneIDForRegion(region string) string { - if region == "" { - region = "us-east-1" - } - return hostedZoneIDsMap[region] } diff --git a/builtin/providers/aws/hosted_zones_test.go b/builtin/providers/aws/hosted_zones_test.go index 3f7818037972..d331a7b8ffb2 100644 --- a/builtin/providers/aws/hosted_zones_test.go +++ b/builtin/providers/aws/hosted_zones_test.go @@ -12,11 +12,6 @@ func TestHostedZoneIDForRegion(t *testing.T) { t.Fatalf("bad: %s", r) } - // Empty string should default to us-east-1 - if r := HostedZoneIDForRegion(""); r != "Z3AQBSTGFYJSTF" { - t.Fatalf("bad: %s", r) - } - // Bad input should be empty string if r := HostedZoneIDForRegion("not-a-region"); r != "" { t.Fatalf("bad: %s", r) diff --git a/builtin/providers/aws/resource_aws_s3_bucket.go b/builtin/providers/aws/resource_aws_s3_bucket.go index 365521483f00..d550124ef5b8 100644 --- a/builtin/providers/aws/resource_aws_s3_bucket.go +++ b/builtin/providers/aws/resource_aws_s3_bucket.go @@ -168,9 +168,7 @@ func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error { if location.LocationConstraint != nil { region = *location.LocationConstraint } - if region == "" { - region = "us-east-1" - } + region = normalizeRegion(region) if err := d.Set("region", region); err != nil { return err } @@ -302,11 +300,16 @@ func websiteEndpoint(s3conn *s3.S3, d *schema.ResourceData) (string, error) { } func WebsiteEndpointUrl(bucket string, region string) string { + region = normalizeRegion(region) + return fmt.Sprintf("%s.s3-website-%s.amazonaws.com", bucket, region) +} + +func normalizeRegion(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" } - return fmt.Sprintf("%s.s3-website-%s.amazonaws.com", bucket, region) + return region }