From 73651e2c70a61a6a1f904d1e85d3eddee5a5bc92 Mon Sep 17 00:00:00 2001 From: Justin Campbell Date: Fri, 8 May 2015 10:29:47 -0400 Subject: [PATCH] providers/aws: Extract normalizeRegion --- builtin/providers/aws/hosted_zones.go | 4 ---- builtin/providers/aws/hosted_zones_test.go | 5 ----- builtin/providers/aws/resource_aws_s3_bucket.go | 11 +++++++---- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/builtin/providers/aws/hosted_zones.go b/builtin/providers/aws/hosted_zones.go index 4d8eb4bf2..7633e0634 100644 --- a/builtin/providers/aws/hosted_zones.go +++ b/builtin/providers/aws/hosted_zones.go @@ -19,9 +19,5 @@ var hostedZoneIDsMap = map[string]string{ // Returns the hosted zone ID for an S3 website endpoint region. This can be // used as input to the aws_route53_record resource's zone_id argument. 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 3f7818037..d331a7b8f 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 365521483..d550124ef 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 }