providers/aws: Extract normalizeRegion

This commit is contained in:
Justin Campbell 2015-05-08 10:29:47 -04:00
parent 445f92e48a
commit 73651e2c70
3 changed files with 7 additions and 13 deletions

View File

@ -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]
}

View File

@ -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)

View File

@ -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
}