Skip to content

Commit

Permalink
providers/aws: Extract normalizeRegion
Browse files Browse the repository at this point in the history
  • Loading branch information
justincampbell committed May 8, 2015
1 parent 445f92e commit 73651e2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
4 changes: 0 additions & 4 deletions builtin/providers/aws/hosted_zones.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
5 changes: 0 additions & 5 deletions builtin/providers/aws/hosted_zones_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions builtin/providers/aws/resource_aws_s3_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

0 comments on commit 73651e2

Please sign in to comment.