From 69fb093389f9a62c926565e1ee1aed25656440f2 Mon Sep 17 00:00:00 2001 From: Justin Campbell Date: Fri, 8 May 2015 10:29:26 -0400 Subject: [PATCH] providers/aws: Move HostedZoneIDForRegion into TF --- builtin/providers/aws/hosted_zones.go | 23 ++++++++++++++++++ builtin/providers/aws/hosted_zones_test.go | 24 +++++++++++++++++++ .../providers/aws/resource_aws_s3_bucket.go | 2 +- .../aws/resource_aws_s3_bucket_test.go | 2 +- 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 builtin/providers/aws/hosted_zones.go create mode 100644 builtin/providers/aws/hosted_zones_test.go diff --git a/builtin/providers/aws/hosted_zones.go b/builtin/providers/aws/hosted_zones.go new file mode 100644 index 000000000000..e119f9d9e21b --- /dev/null +++ b/builtin/providers/aws/hosted_zones.go @@ -0,0 +1,23 @@ +package aws + +// http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_website_region_endpoints +var hostedZoneIDsMap = map[string]string{ + "us-east-1": "Z3AQBSTGFYJSTF", + "us-west-2": "Z3BJ6K6RIION7M", + "us-west-1": "Z2F56UZL2M1ACD", + "eu-west-1": "Z1BKCTXD74EZPE", + "central-1": "Z21DNDUVLTQW6Q", + "ap-southeast-1": "Z3O0J2DXBE1FTB", + "ap-southeast-2": "Z1WCIGYICN2BYD", + "ap-northeast-1": "Z2M4EHUR26P7ZW", + "sa-east-1": "Z7KQH4QJS55SO", + "us-gov-west-1": "Z31GFT0UA1I2HV", +} + +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 new file mode 100644 index 000000000000..3f7818037972 --- /dev/null +++ b/builtin/providers/aws/hosted_zones_test.go @@ -0,0 +1,24 @@ +package aws + +import ( + "testing" +) + +func TestHostedZoneIDForRegion(t *testing.T) { + if r := HostedZoneIDForRegion("us-east-1"); r != "Z3AQBSTGFYJSTF" { + t.Fatalf("bad: %s", r) + } + if r := HostedZoneIDForRegion("ap-southeast-2"); r != "Z1WCIGYICN2BYD" { + 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 11f507fdcf23..365521483f00 100644 --- a/builtin/providers/aws/resource_aws_s3_bucket.go +++ b/builtin/providers/aws/resource_aws_s3_bucket.go @@ -176,7 +176,7 @@ func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error { } // Add the hosted zone ID for this bucket's region as an attribute - hostedZoneID := s3.HostedZoneIDForRegion(region) + hostedZoneID := HostedZoneIDForRegion(region) if err := d.Set("hosted_zone_id", hostedZoneID); err != nil { return err } diff --git a/builtin/providers/aws/resource_aws_s3_bucket_test.go b/builtin/providers/aws/resource_aws_s3_bucket_test.go index 1d7109d210c3..1b41d76eaf9f 100644 --- a/builtin/providers/aws/resource_aws_s3_bucket_test.go +++ b/builtin/providers/aws/resource_aws_s3_bucket_test.go @@ -24,7 +24,7 @@ func TestAccAWSS3Bucket_basic(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"), resource.TestCheckResourceAttr( - "aws_s3_bucket.bucket", "hosted_zone_id", s3.HostedZoneIDForRegion("us-west-2")), + "aws_s3_bucket.bucket", "hosted_zone_id", HostedZoneIDForRegion("us-west-2")), resource.TestCheckResourceAttr( "aws_s3_bucket.bucket", "region", "us-west-2"), resource.TestCheckResourceAttr(