From cdf19444f42f00271cb8554be74b6a34121bef8b Mon Sep 17 00:00:00 2001 From: Jukie Date: Thu, 18 Apr 2019 22:55:25 -0400 Subject: [PATCH 01/10] add nlb zone id's and elb_type argument --- aws/data_source_aws_elb_hosted_zone_id.go | 68 +++++++++++++++-------- 1 file changed, 45 insertions(+), 23 deletions(-) diff --git a/aws/data_source_aws_elb_hosted_zone_id.go b/aws/data_source_aws_elb_hosted_zone_id.go index 3fec3f2eab3d..c27c71983f7b 100644 --- a/aws/data_source_aws_elb_hosted_zone_id.go +++ b/aws/data_source_aws_elb_hosted_zone_id.go @@ -3,30 +3,40 @@ package aws import ( "fmt" + "github.com/aws/aws-sdk-go/service/elbv2" "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/helper/validation" ) -// See http://docs.aws.amazon.com/general/latest/gr/rande.html#elb_region -var elbHostedZoneIdPerRegionMap = map[string]string{ - "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": "638102146993", - "eu-central-1": "Z215JYRZR1TBD5", - "eu-north-1": "Z23TAZ6LKFMNIO", - "eu-west-1": "Z32O12XQLNTSW2", - "eu-west-2": "ZHURV8PSTC4K8", - "eu-west-3": "Z3Q77PNBQS71R4", - "sa-east-1": "Z2P70J7HTTTPLU", - "us-east-1": "Z35SXDOTRQ7X7K", - "us-east-2": "Z3AADJGX6KTTL2", - "us-gov-west-1": "048591011584", - "us-west-1": "Z368ELLRRE2KJ0", - "us-west-2": "Z1H1FL5HABSF5", +// See https://docs.aws.amazon.com/general/latest/gr/rande.html#elb_region +// First index is Application/Classic LB id's, second index is NLB id's +var elbHostedZoneIdPerRegionMap = map[string][]string{ + "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": {"638102146993", "Z3QFB96KMJ7ED6"}, + "eu-central-1": {"Z215JYRZR1TBD5", "ZQEIKTCZ8352D"}, + "eu-north-1": {"Z23TAZ6LKFMNIO", "Z3F0SRJ5LGBH90"}, + "eu-west-1": {"Z32O12XQLNTSW2", "Z1UDT6IFJ4EJM"}, + "eu-west-2": {"ZHURV8PSTC4K8", "Z2IFOLAFXWLO4F"}, + "eu-west-3": {"Z3Q77PNBQS71R4", "ZD4D7Y8KGAS4G"}, + "sa-east-1": {"Z2P70J7HTTTPLU", "Z1CMS0P5QUZ6D5"}, + "us-east-1": {"Z35SXDOTRQ7X7K", "ZTK26PT1VY4CU"}, + "us-east-2": {"Z3AADJGX6KTTL2", "Z26RNL4JYFTOTI"}, + "us-gov-west-1": {"048591011584", "ZLMOA37VPKANP"}, + "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 { @@ -38,6 +48,11 @@ func dataSourceAwsElbHostedZoneId() *schema.Resource { Type: schema.TypeString, Optional: true, }, + "elb_type": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice(validElbTypes, false), + }, }, } } @@ -47,9 +62,16 @@ func dataSourceAwsElbHostedZoneIdRead(d *schema.ResourceData, meta interface{}) if v, ok := d.GetOk("region"); ok { region = v.(string) } - + var i int + if v, ok := d.GetOk("elb_type"); ok { + if v.(string) == "classic" || v.(string) == "application" { + i = 0 + } else if v.(string) == "network" { + i = 1 + } + } if zoneId, ok := elbHostedZoneIdPerRegionMap[region]; ok { - d.SetId(zoneId) + d.SetId(zoneId[i]) return nil } From 7306d511a60ca85de0d3247b7e124c2e3191006b Mon Sep 17 00:00:00 2001 From: Jukie Date: Thu, 18 Apr 2019 22:56:24 -0400 Subject: [PATCH 02/10] Update acceptance tests to include elb_type argument --- aws/data_source_aws_elb_hosted_zone_id_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 af3195673f3d..1a001c9cfa6c 100644 --- a/aws/data_source_aws_elb_hosted_zone_id_test.go +++ b/aws/data_source_aws_elb_hosted_zone_id_test.go @@ -20,7 +20,7 @@ func TestAccAWSElbHostedZoneId_basic(t *testing.T) { { Config: testAccCheckAwsElbHostedZoneIdExplicitRegionConfig, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("data.aws_elb_hosted_zone_id.regional", "id", "Z32O12XQLNTSW2"), + resource.TestCheckResourceAttr("data.aws_elb_hosted_zone_id.regional", "id", "Z1UDT6IFJ4EJM"), ), }, }, @@ -28,11 +28,14 @@ func TestAccAWSElbHostedZoneId_basic(t *testing.T) { } const testAccCheckAwsElbHostedZoneIdConfig = ` -data "aws_elb_hosted_zone_id" "main" { } +data "aws_elb_hosted_zone_id" "main" { + elb_type = "application" +} ` const testAccCheckAwsElbHostedZoneIdExplicitRegionConfig = ` data "aws_elb_hosted_zone_id" "regional" { region = "eu-west-1" + elb_type = "network" } ` From 298a5224a92ef01494b1f3e87435e80541374285 Mon Sep 17 00:00:00 2001 From: Jukie Date: Thu, 18 Apr 2019 23:09:03 -0400 Subject: [PATCH 03/10] Update docs for 'elb_type' --- website/docs/d/elb_hosted_zone_id.html.markdown | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/website/docs/d/elb_hosted_zone_id.html.markdown b/website/docs/d/elb_hosted_zone_id.html.markdown index e92c9307188a..5779e6903fbc 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` - (required) Type of ELB the HostedZoneId is being requested for. +Valid values: + * `application` + * `classic` + * `network` ## Attributes Reference From b0d8391ff3dcc34ed2f231bdf7ee8009fa9274f0 Mon Sep 17 00:00:00 2001 From: Jukie Date: Sun, 21 Apr 2019 12:11:23 -0400 Subject: [PATCH 04/10] let elb_type be optional to avoid a breaking change --- aws/data_source_aws_elb_hosted_zone_id.go | 4 ++- ...data_source_aws_elb_hosted_zone_id_test.go | 34 +++++++++++++------ .../docs/d/elb_hosted_zone_id.html.markdown | 2 +- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/aws/data_source_aws_elb_hosted_zone_id.go b/aws/data_source_aws_elb_hosted_zone_id.go index c27c71983f7b..66c294c13b34 100644 --- a/aws/data_source_aws_elb_hosted_zone_id.go +++ b/aws/data_source_aws_elb_hosted_zone_id.go @@ -50,7 +50,7 @@ func dataSourceAwsElbHostedZoneId() *schema.Resource { }, "elb_type": { Type: schema.TypeString, - Required: true, + Optional: true, ValidateFunc: validation.StringInSlice(validElbTypes, false), }, }, @@ -69,6 +69,8 @@ func dataSourceAwsElbHostedZoneIdRead(d *schema.ResourceData, meta interface{}) } else if v.(string) == "network" { i = 1 } + } else { + i = 0 } if zoneId, ok := elbHostedZoneIdPerRegionMap[region]; ok { d.SetId(zoneId[i]) 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 1a001c9cfa6c..3a4cbc08862a 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/helper/resource" @@ -12,30 +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", "Z1UDT6IFJ4EJM"), + 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", "Z2IFOLAFXWLO4F"), ), }, }, }) } -const testAccCheckAwsElbHostedZoneIdConfig = ` -data "aws_elb_hosted_zone_id" "main" { - elb_type = "application" +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" - elb_type = "network" + 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 5779e6903fbc..6f287f9fb13e 100644 --- a/website/docs/d/elb_hosted_zone_id.html.markdown +++ b/website/docs/d/elb_hosted_zone_id.html.markdown @@ -33,7 +33,7 @@ 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` - (required) Type of ELB the HostedZoneId is being requested for. +* `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` From b5e06f320a4586caba9a199a7baa48fd0e64f2de Mon Sep 17 00:00:00 2001 From: Jukie Date: Wed, 15 May 2019 08:11:06 -0400 Subject: [PATCH 05/10] add ap-east-1 region --- aws/data_source_aws_elb_hosted_zone_id.go | 1 + 1 file changed, 1 insertion(+) diff --git a/aws/data_source_aws_elb_hosted_zone_id.go b/aws/data_source_aws_elb_hosted_zone_id.go index 66c294c13b34..ce718b3414b1 100644 --- a/aws/data_source_aws_elb_hosted_zone_id.go +++ b/aws/data_source_aws_elb_hosted_zone_id.go @@ -11,6 +11,7 @@ import ( // See https://docs.aws.amazon.com/general/latest/gr/rande.html#elb_region // First index is Application/Classic LB id's, second index is NLB id's var elbHostedZoneIdPerRegionMap = map[string][]string{ + "ap-east-1": {"Z3DQVH9N71FHZ0", "Z12Y7K3UBGUAD1"}, "ap-northeast-1": {"Z14GRHDCWA56QT", "Z31USIVHYNEOWT"}, "ap-northeast-2": {"ZWKZPGTI48KDX", "ZIBE1TIR4HY56"}, "ap-northeast-3": {"Z5LXEXXYW11ES", "Z1GWIQ4HH19I5X"}, From 1a4709d7d5224d73cd0969fa44cd6a6007be63ed Mon Sep 17 00:00:00 2001 From: Jukie Date: Mon, 30 Sep 2019 17:48:44 -0400 Subject: [PATCH 06/10] Add correct hosted zone id's --- aws/data_source_aws_elb_hosted_zone_id.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/aws/data_source_aws_elb_hosted_zone_id.go b/aws/data_source_aws_elb_hosted_zone_id.go index ce718b3414b1..7a4cc4ea85cb 100644 --- a/aws/data_source_aws_elb_hosted_zone_id.go +++ b/aws/data_source_aws_elb_hosted_zone_id.go @@ -19,16 +19,17 @@ var elbHostedZoneIdPerRegionMap = map[string][]string{ "ap-southeast-1": {"Z1LMS91P8CMLE5", "ZKVM4W9LS7TM"}, "ap-southeast-2": {"Z1GM3OXH4ZPM65", "ZCT6FZBF4DROD"}, "ca-central-1": {"ZQSVJUPU6J1EY", "Z2EPGBW3API2WT"}, - "cn-north-1": {"638102146993", "Z3QFB96KMJ7ED6"}, - "eu-central-1": {"Z215JYRZR1TBD5", "ZQEIKTCZ8352D"}, - "eu-north-1": {"Z23TAZ6LKFMNIO", "Z3F0SRJ5LGBH90"}, - "eu-west-1": {"Z32O12XQLNTSW2", "Z1UDT6IFJ4EJM"}, - "eu-west-2": {"ZHURV8PSTC4K8", "Z2IFOLAFXWLO4F"}, - "eu-west-3": {"Z3Q77PNBQS71R4", "ZD4D7Y8KGAS4G"}, - "sa-east-1": {"Z2P70J7HTTTPLU", "Z1CMS0P5QUZ6D5"}, - "us-east-1": {"Z35SXDOTRQ7X7K", "ZTK26PT1VY4CU"}, - "us-east-2": {"Z3AADJGX6KTTL2", "Z26RNL4JYFTOTI"}, - "us-gov-west-1": {"048591011584", "ZLMOA37VPKANP"}, + "cn-north-1": {"3BX2TMKNYI13Y", "Z3QFB96KMJ7ED6"}, + "cn-northwest-1": {"Z3BX2TMKNYI13Y", "ZQEIKTCZ8352D"}, + "eu-central-1": {"Z215JYRZR1TBD5", "Z3F0SRJ5LGBH90"}, + "eu-north-1": {"Z23TAZ6LKFMNIO", "Z1UDT6IFJ4EJM"}, + "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-west-1": {"Z368ELLRRE2KJ0", "Z24FKFUX50B4VW"}, "us-west-2": {"Z1H1FL5HABSF5", "Z18D5FSROUN65G"}, } From 1b55cd07b7cd8a48600735cb08a27dcd45076ec6 Mon Sep 17 00:00:00 2001 From: Jukie Date: Mon, 30 Sep 2019 18:02:05 -0400 Subject: [PATCH 07/10] Update tests with correct id's --- aws/data_source_aws_elb_hosted_zone_id_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3a4cbc08862a..d267b53f78c5 100644 --- a/aws/data_source_aws_elb_hosted_zone_id_test.go +++ b/aws/data_source_aws_elb_hosted_zone_id_test.go @@ -33,7 +33,7 @@ func TestAccAWSElbHostedZoneId_basic(t *testing.T) { { Config: testAccCheckAwsElbHostedZoneIdExplicitConfig("eu-west-2", "network"), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("data.aws_elb_hosted_zone_id.regional", "id", "Z2IFOLAFXWLO4F"), + resource.TestCheckResourceAttr("data.aws_elb_hosted_zone_id.regional", "id", "ZD4D7Y8KGAS4G"), ), }, }, From fd617b6fe7d3e91299e0c5b6f6002fb7fad14795 Mon Sep 17 00:00:00 2001 From: Jukie Date: Tue, 1 Oct 2019 18:42:26 -0400 Subject: [PATCH 08/10] Update with more descriptive variable name --- aws/data_source_aws_elb_hosted_zone_id.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/aws/data_source_aws_elb_hosted_zone_id.go b/aws/data_source_aws_elb_hosted_zone_id.go index 563d63b25624..a2df8e879e23 100644 --- a/aws/data_source_aws_elb_hosted_zone_id.go +++ b/aws/data_source_aws_elb_hosted_zone_id.go @@ -65,18 +65,18 @@ func dataSourceAwsElbHostedZoneIdRead(d *schema.ResourceData, meta interface{}) if v, ok := d.GetOk("region"); ok { region = v.(string) } - var i int + var lbTypeIndex int if v, ok := d.GetOk("elb_type"); ok { if v.(string) == "classic" || v.(string) == "application" { - i = 0 + lbTypeIndex = 0 } else if v.(string) == "network" { - i = 1 + lbTypeIndex = 1 } } else { - i = 0 + lbTypeIndex = 0 } if zoneId, ok := elbHostedZoneIdPerRegionMap[region]; ok { - d.SetId(zoneId[i]) + d.SetId(zoneId[lbTypeIndex]) return nil } From 47c03fa0b9f0a03bdeacd1e86c50484dcfa9f283 Mon Sep 17 00:00:00 2001 From: Jukie Date: Fri, 11 Oct 2019 17:09:50 -0400 Subject: [PATCH 09/10] Import package changes --- aws/data_source_aws_elb_hosted_zone_id.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aws/data_source_aws_elb_hosted_zone_id.go b/aws/data_source_aws_elb_hosted_zone_id.go index a2df8e879e23..eec78e045fd6 100644 --- a/aws/data_source_aws_elb_hosted_zone_id.go +++ b/aws/data_source_aws_elb_hosted_zone_id.go @@ -4,8 +4,8 @@ import ( "fmt" "github.com/aws/aws-sdk-go/service/elbv2" - "github.com/hashicorp/terraform/helper/schema" - "github.com/hashicorp/terraform/helper/validation" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" ) // See https://docs.aws.amazon.com/general/latest/gr/rande.html#elb_region From e186abd05a1da088b3a16c112d3d3cea255fa536 Mon Sep 17 00:00:00 2001 From: Jukie Date: Sun, 3 May 2020 13:11:21 -0400 Subject: [PATCH 10/10] Apply website lint fixes --- website/docs/d/elb_hosted_zone_id.html.markdown | 2 +- website/docs/r/waf_sql_injection_match_set.html.markdown | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/website/docs/d/elb_hosted_zone_id.html.markdown b/website/docs/d/elb_hosted_zone_id.html.markdown index 9b1fa273193d..07561dbf9e01 100644 --- a/website/docs/d/elb_hosted_zone_id.html.markdown +++ b/website/docs/d/elb_hosted_zone_id.html.markdown @@ -33,7 +33,7 @@ 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) +* `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` 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 04a5e2603550..08da2041fb7b 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 +```