Skip to content

Commit

Permalink
Merge branch 'b-route53-zone-domain' into b-route53-zone-ses-domain
Browse files Browse the repository at this point in the history
  • Loading branch information
anGie44 committed Jul 24, 2020
2 parents a315fb2 + 6b99c3c commit 6c2fba8
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 20 deletions.
4 changes: 2 additions & 2 deletions aws/data_source_aws_route53_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions aws/data_source_aws_route53_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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" {
Expand All @@ -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}"
}
Expand Down Expand Up @@ -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}"
Expand Down
19 changes: 12 additions & 7 deletions aws/resource_aws_route53_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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), ".")
}

Expand Down
6 changes: 3 additions & 3 deletions aws/resource_aws_route53_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestCleanChangeID(t *testing.T) {
}
}

func TestCleanDomainName(t *testing.T) {
func TestTrimTrailingPeriod(t *testing.T) {
cases := []struct {
Input, Output string
}{
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/route53_zone.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 4 additions & 3 deletions website/docs/guides/version-3-upgrade.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 6c2fba8

Please sign in to comment.