diff --git a/aws/data_source_aws_route53_zone.go b/aws/data_source_aws_route53_zone.go index 247cead6a3e..3ad11ae3405 100644 --- a/aws/data_source_aws_route53_zone.go +++ b/aws/data_source_aws_route53_zone.go @@ -105,7 +105,7 @@ func dataSourceAwsRoute53ZoneRead(d *schema.ResourceData, meta interface{}) erro hostedZoneFound = hostedZone break // we check if the name is the same as requested and if private zone field is the same as requested or if there is a vpc_id - } else if cleanDomainName(aws.StringValue(hostedZone.Name)) == name && (aws.BoolValue(hostedZone.Config.PrivateZone) == d.Get("private_zone").(bool) || (aws.BoolValue(hostedZone.Config.PrivateZone) && vpcIdExists)) { + } else if (trimTrailingPeriod(aws.StringValue(hostedZone.Name)) == trimTrailingPeriod(name)) && (aws.BoolValue(hostedZone.Config.PrivateZone) == d.Get("private_zone").(bool) || (aws.BoolValue(hostedZone.Config.PrivateZone) && vpcIdExists)) { matchingVPC := false if vpcIdExists { reqHostedZone := &route53.GetHostedZoneInput{} @@ -160,7 +160,7 @@ func dataSourceAwsRoute53ZoneRead(d *schema.ResourceData, meta interface{}) erro d.Set("zone_id", idHostedZone) // To be consistent with other AWS services (e.g. ACM) that do not accept a trailing period, // we remove the suffix from the Hosted Zone Name returned from the API - d.Set("name", cleanDomainName(aws.StringValue(hostedZoneFound.Name))) + d.Set("name", trimTrailingPeriod(aws.StringValue(hostedZoneFound.Name))) d.Set("comment", hostedZoneFound.Config.Comment) d.Set("private_zone", hostedZoneFound.Config.PrivateZone) d.Set("caller_reference", hostedZoneFound.CallerReference) diff --git a/aws/data_source_aws_route53_zone_test.go b/aws/data_source_aws_route53_zone_test.go index 237ba14a579..4a5dad3feea 100644 --- a/aws/data_source_aws_route53_zone_test.go +++ b/aws/data_source_aws_route53_zone_test.go @@ -125,7 +125,7 @@ func TestAccDataSourceAwsRoute53Zone_serviceDiscovery(t *testing.T) { func testAccDataSourceAwsRoute53ZoneConfigId(rInt int) string { return fmt.Sprintf(` resource "aws_route53_zone" "test" { - name = "terraformtestacchz-%[1]d.com" + name = "terraformtestacchz-%[1]d.com." } data "aws_route53_zone" "test" { @@ -137,7 +137,7 @@ data "aws_route53_zone" "test" { func testAccDataSourceAwsRoute53ZoneConfigName(rInt int) string { return fmt.Sprintf(` resource "aws_route53_zone" "test" { - name = "terraformtestacchz-%[1]d.com" + name = "terraformtestacchz-%[1]d.com." } data "aws_route53_zone" "test" { @@ -157,7 +157,7 @@ resource "aws_vpc" "test" { } resource "aws_route53_zone" "test" { - name = "terraformtestacchz-%[1]d.com" + name = "terraformtestacchz-%[1]d.com." vpc { vpc_id = "${aws_vpc.test.id}" } @@ -191,7 +191,7 @@ resource "aws_vpc" "test" { } resource "aws_route53_zone" "test" { - name = "test.acc-%[1]d" + name = "test.acc-%[1]d." vpc { vpc_id = "${aws_vpc.test.id}" diff --git a/aws/resource_aws_route53_zone.go b/aws/resource_aws_route53_zone.go index 22199c02df3..0ddde7875e0 100644 --- a/aws/resource_aws_route53_zone.go +++ b/aws/resource_aws_route53_zone.go @@ -30,10 +30,13 @@ func resourceAwsRoute53Zone() *schema.Resource { Schema: map[string]*schema.Schema{ "name": { // AWS Provider 3.0.0 - trailing period removed from name - // returned from API, no longer requiring custom DiffSuppressFunc - Type: schema.TypeString, - Required: true, - ForceNew: true, + // returned from API, no longer requiring custom DiffSuppressFunc; + // instead a StateFunc allows input to be provided + // with or without the trailing period + Type: schema.TypeString, + Required: true, + ForceNew: true, + StateFunc: trimTrailingPeriod, }, "comment": { @@ -182,7 +185,7 @@ func resourceAwsRoute53ZoneRead(d *schema.ResourceData, meta interface{}) error d.Set("delegation_set_id", "") // To be consistent with other AWS services (e.g. ACM) that do not accept a trailing period, // we remove the suffix from the Hosted Zone Name returned from the API - d.Set("name", cleanDomainName(aws.StringValue(output.HostedZone.Name))) + d.Set("name", trimTrailingPeriod(aws.StringValue(output.HostedZone.Name))) d.Set("zone_id", cleanZoneID(aws.StringValue(output.HostedZone.Id))) var nameServers []string @@ -392,8 +395,10 @@ func cleanZoneID(ID string) string { return strings.TrimPrefix(ID, "/hostedzone/") } -// cleanDomainName is used to remove the trailing period -func cleanDomainName(v interface{}) string { +// trimTrailingPeriod is used to remove the trailing period +// of "name" or "domain name" attributes often returned from +// the Route53 API or provided as user input +func trimTrailingPeriod(v interface{}) string { return strings.TrimSuffix(v.(string), ".") } diff --git a/aws/resource_aws_route53_zone_test.go b/aws/resource_aws_route53_zone_test.go index dcc336395a6..e9fb8136ca9 100644 --- a/aws/resource_aws_route53_zone_test.go +++ b/aws/resource_aws_route53_zone_test.go @@ -48,7 +48,7 @@ func TestCleanChangeID(t *testing.T) { } } -func TestCleanDomainName(t *testing.T) { +func TestTrimTrailingPeriod(t *testing.T) { cases := []struct { Input, Output string }{ @@ -58,7 +58,7 @@ func TestCleanDomainName(t *testing.T) { } for _, tc := range cases { - actual := cleanDomainName(tc.Input) + actual := trimTrailingPeriod(tc.Input) if actual != tc.Output { t.Fatalf("input: %s\noutput: %s", tc.Input, actual) } @@ -553,7 +553,7 @@ func testAccCheckDomainName(zone *route53.GetHostedZoneOutput, domain string) re // To compare the Hosted Zone Domain Name returned from the API // and that stored in the resource, it too must by cleaned of // the trailing period - if cleanDomainName(aws.StringValue(zone.HostedZone.Name)) == domain { + if trimTrailingPeriod(aws.StringValue(zone.HostedZone.Name)) == domain { return nil } diff --git a/website/docs/d/route53_zone.html.markdown b/website/docs/d/route53_zone.html.markdown index b3cc4c769f8..655f3d76525 100644 --- a/website/docs/d/route53_zone.html.markdown +++ b/website/docs/d/route53_zone.html.markdown @@ -19,7 +19,7 @@ The following example shows how to get a Hosted Zone from its name and from this ```hcl data "aws_route53_zone" "selected" { - name = "test.com" + name = "test.com." private_zone = true } diff --git a/website/docs/guides/version-3-upgrade.html.md b/website/docs/guides/version-3-upgrade.html.md index b3ece2863c9..6f5cc2e6d98 100644 --- a/website/docs/guides/version-3-upgrade.html.md +++ b/website/docs/guides/version-3-upgrade.html.md @@ -169,8 +169,8 @@ output "lambda_result" { ### Removal of name trailing period -Previously the data-source returned the Hosted Zone Domain Name directly from the API, which included a `.` suffix. This proves difficult when many other AWS services do not accept this trailing period (e.g. ACM Certificate). This period is now automatically removed. For example, when the attribute would previously return a Hosted Zone Domain Name such as `www.example.com.`, the attribute now will be returned as `www.example.com`. -When providing a `name` to the data-source, this too should be given without the trailing period to match the updated naming convention. +Previously the data-source returned the Hosted Zone Domain Name directly from the API, which included a `.` suffix. This proves difficult when many other AWS services do not accept this trailing period (e.g. ACM Certificate). This period is now automatically removed. For example, when the attribute would previously return a Hosted Zone Domain Name such as `example.com.`, the attribute now will be returned as `example.com`. +While the returned value will omit the trailing period, use of configurations with trailing periods will not be interrupted. ## Resource: aws_acm_certificate @@ -502,7 +502,8 @@ Previously when the `min_capacity` argument in a `scaling_configuration` block w ### Removal of name trailing period -Previously the resource returned the Hosted Zone Domain Name directly from the API, which included a `.` suffix. This proves difficult when many other AWS services do not accept this trailing period (e.g. ACM Certificate). This period is now automatically removed. For example, when the attribute would previously return a Hosted Zone Domain Name such as `www.example.com.`, the attribute now will be returned as `www.example.com` +Previously the resource returned the Hosted Zone Domain Name directly from the API, which included a `.` suffix. This proves difficult when many other AWS services do not accept this trailing period (e.g. ACM Certificate). This period is now automatically removed. For example, when the attribute would previously return a Hosted Zone Domain Name such as `example.com.`, the attribute now will be returned as `example.com` +While the returned value will omit the trailing period, use of configurations with trailing periods will not be interrupted. ## Resource: aws_s3_bucket