diff --git a/aws/data_source_aws_elb_hosted_zone_id.go b/aws/data_source_aws_elb_hosted_zone_id.go index e16d546f29f..4cb6110979f 100644 --- a/aws/data_source_aws_elb_hosted_zone_id.go +++ b/aws/data_source_aws_elb_hosted_zone_id.go @@ -3,37 +3,47 @@ package aws import ( "fmt" + "github.com/aws/aws-sdk-go/service/elbv2" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" ) -// See http://docs.aws.amazon.com/general/latest/gr/rande.html#elb_region +// See https://docs.aws.amazon.com/general/latest/gr/rande.html#elb_region // See https://docs.amazonaws.cn/en_us/general/latest/gr/rande.html#elb_region -var elbHostedZoneIdPerRegionMap = map[string]string{ - "af-south-1": "Z268VQBMOI5EKX", - "ap-east-1": "Z3DQVH9N71FHZ0", - "ap-northeast-1": "Z14GRHDCWA56QT", - "ap-northeast-2": "ZWKZPGTI48KDX", - "ap-northeast-3": "Z5LXEXXYW11ES", - "ap-south-1": "ZP97RAFLXTNZK", - "ap-southeast-1": "Z1LMS91P8CMLE5", - "ap-southeast-2": "Z1GM3OXH4ZPM65", - "ca-central-1": "ZQSVJUPU6J1EY", - "cn-north-1": "Z3BX2TMKNYI13Y", - "cn-northwest-1": "Z3BX2TMKNYI13Y", - "eu-central-1": "Z215JYRZR1TBD5", - "eu-north-1": "Z23TAZ6LKFMNIO", - "eu-south-1": "Z3ULH7SSC9OV64", - "eu-west-1": "Z32O12XQLNTSW2", - "eu-west-2": "ZHURV8PSTC4K8", - "eu-west-3": "Z3Q77PNBQS71R4", - "me-south-1": "ZS929ML54UICD", - "sa-east-1": "Z2P70J7HTTTPLU", - "us-east-1": "Z35SXDOTRQ7X7K", - "us-east-2": "Z3AADJGX6KTTL2", - "us-gov-east-1": "Z166TLBEWOO7G0", - "us-gov-west-1": "Z33AYJ8TM3BH4J", - "us-west-1": "Z368ELLRRE2KJ0", - "us-west-2": "Z1H1FL5HABSF5", +// First index is Application/Classic LB id's, second index is NLB id's +var elbHostedZoneIdPerRegionMap = map[string][]string{ + "af-south-1": {"Z268VQBMOI5EKX", "Z203XCE67M25HM"}, + "ap-east-1": {"Z3DQVH9N71FHZ0", "Z12Y7K3UBGUAD1"}, + "ap-northeast-1": {"Z14GRHDCWA56QT", "Z31USIVHYNEOWT"}, + "ap-northeast-2": {"ZWKZPGTI48KDX", "ZIBE1TIR4HY56"}, + "ap-northeast-3": {"Z5LXEXXYW11ES", "Z1GWIQ4HH19I5X"}, + "ap-south-1": {"ZP97RAFLXTNZK", "ZVDDRBQ08TROA"}, + "ap-southeast-1": {"Z1LMS91P8CMLE5", "ZKVM4W9LS7TM"}, + "ap-southeast-2": {"Z1GM3OXH4ZPM65", "ZCT6FZBF4DROD"}, + "ca-central-1": {"ZQSVJUPU6J1EY", "Z2EPGBW3API2WT"}, + "cn-north-1": {"Z1GDH35T77C1KE", "Z3QFB96KMJ7ED6"}, + "cn-northwest-1": {"ZM7IZAIOVVDZF", "ZQEIKTCZ8352D"}, + "eu-central-1": {"Z215JYRZR1TBD5", "Z3F0SRJ5LGBH90"}, + "eu-north-1": {"Z23TAZ6LKFMNIO", "Z1UDT6IFJ4EJM"}, + "eu-south-1": {"Z3ULH7SSC9OV64", "Z23146JA1KNAFP"}, + "eu-west-1": {"Z32O12XQLNTSW2", "Z2IFOLAFXWLO4F"}, + "eu-west-2": {"ZHURV8PSTC4K8", "ZD4D7Y8KGAS4G"}, + "eu-west-3": {"Z3Q77PNBQS71R4", "Z1CMS0P5QUZ6D5"}, + "me-south-1": {"ZS929ML54UICD", "Z3QSRYVP46NYYV"}, + "sa-east-1": {"Z2P70J7HTTTPLU", "ZTK26PT1VY4CU"}, + "us-east-1": {"Z35SXDOTRQ7X7K", "Z26RNL4JYFTOTI"}, + "us-east-2": {"Z3AADJGX6KTTL2", "ZLMOA37VPKANP"}, + "us-gov-east-1": {"Z166TLBEWOO7G0", "Z1ZSMQQ6Q24QQ8"}, + "us-gov-west-1": {"Z33AYJ8TM3BH4J", "ZMG1MZ2THAWF1"}, + "us-west-1": {"Z368ELLRRE2KJ0", "Z24FKFUX50B4VW"}, + "us-west-2": {"Z1H1FL5HABSF5", "Z18D5FSROUN65G"}, +} + +var validElbTypes = []string{ + // elbv2 and elb don't have an option for classic + elbv2.LoadBalancerTypeEnumApplication, + "classic", + elbv2.LoadBalancerTypeEnumNetwork, } func dataSourceAwsElbHostedZoneId() *schema.Resource { @@ -45,6 +55,11 @@ func dataSourceAwsElbHostedZoneId() *schema.Resource { Type: schema.TypeString, Optional: true, }, + "elb_type": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice(validElbTypes, false), + }, }, } } @@ -54,9 +69,18 @@ func dataSourceAwsElbHostedZoneIdRead(d *schema.ResourceData, meta interface{}) if v, ok := d.GetOk("region"); ok { region = v.(string) } - + var lbTypeIndex int + if v, ok := d.GetOk("elb_type"); ok { + if v.(string) == "classic" || v.(string) == "application" { + lbTypeIndex = 0 + } else if v.(string) == "network" { + lbTypeIndex = 1 + } + } else { + lbTypeIndex = 0 + } if zoneId, ok := elbHostedZoneIdPerRegionMap[region]; ok { - d.SetId(zoneId) + d.SetId(zoneId[lbTypeIndex]) return nil } diff --git a/aws/data_source_aws_elb_hosted_zone_id_test.go b/aws/data_source_aws_elb_hosted_zone_id_test.go index d5b622a31c6..a5b9f73e203 100644 --- a/aws/data_source_aws_elb_hosted_zone_id_test.go +++ b/aws/data_source_aws_elb_hosted_zone_id_test.go @@ -1,6 +1,7 @@ package aws import ( + "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" @@ -12,27 +13,43 @@ func TestAccAWSElbHostedZoneId_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccCheckAwsElbHostedZoneIdConfig, + Config: testAccCheckAwsElbHostedZoneIdBasicConfig, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("data.aws_elb_hosted_zone_id.main", "id", "Z1H1FL5HABSF5"), ), }, { - Config: testAccCheckAwsElbHostedZoneIdExplicitRegionConfig, + Config: testAccCheckAwsElbHostedZoneIdExplicitConfig("us-east-1", "application"), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("data.aws_elb_hosted_zone_id.regional", "id", "Z32O12XQLNTSW2"), + resource.TestCheckResourceAttr("data.aws_elb_hosted_zone_id.regional", "id", "Z35SXDOTRQ7X7K"), + ), + }, + { + Config: testAccCheckAwsElbHostedZoneIdExplicitConfig("us-west-1", "classic"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.aws_elb_hosted_zone_id.regional", "id", "Z368ELLRRE2KJ0"), + ), + }, + { + Config: testAccCheckAwsElbHostedZoneIdExplicitConfig("eu-west-2", "network"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.aws_elb_hosted_zone_id.regional", "id", "ZD4D7Y8KGAS4G"), ), }, }, }) } -const testAccCheckAwsElbHostedZoneIdConfig = ` -data "aws_elb_hosted_zone_id" "main" { } +const testAccCheckAwsElbHostedZoneIdBasicConfig = ` +data "aws_elb_hosted_zone_id" "main" { +} ` -const testAccCheckAwsElbHostedZoneIdExplicitRegionConfig = ` +func testAccCheckAwsElbHostedZoneIdExplicitConfig(region, elbType string) string { + return fmt.Sprintf(` data "aws_elb_hosted_zone_id" "regional" { - region = "eu-west-1" + region = "%s" + elb_type = "%s" +} +`, region, elbType) } -` diff --git a/website/docs/d/elb_hosted_zone_id.html.markdown b/website/docs/d/elb_hosted_zone_id.html.markdown index c011318789b..07561dbf9e0 100644 --- a/website/docs/d/elb_hosted_zone_id.html.markdown +++ b/website/docs/d/elb_hosted_zone_id.html.markdown @@ -33,6 +33,11 @@ resource "aws_route53_record" "www" { * `region` - (Optional) Name of the region whose AWS ELB HostedZoneId is desired. Defaults to the region from the AWS provider configuration. +* `elb_type` - (Optional) Type of ELB the HostedZoneId is being requested for. Defaults to `application`/`classic` (Both use the same HostedZoneId) +Valid values: + * `application` + * `classic` + * `network` ## Attributes Reference diff --git a/website/docs/r/waf_sql_injection_match_set.html.markdown b/website/docs/r/waf_sql_injection_match_set.html.markdown index 04a5e260355..08da2041fb7 100644 --- a/website/docs/r/waf_sql_injection_match_set.html.markdown +++ b/website/docs/r/waf_sql_injection_match_set.html.markdown @@ -70,4 +70,4 @@ AWS WAF SQL Injection Match Set can be imported using their ID, e.g. ``` $ terraform import aws_waf_sql_injection_match_set.example a1b2c3d4-d5f6-7777-8888-9999aaaabbbbcccc -``` \ No newline at end of file +```