Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/aws_route53_record: Correct fqdn for wildcard records #40868

Merged
merged 11 commits into from
Jan 10, 2025
3 changes: 3 additions & 0 deletions .changelog/40868.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_route53_record: Correct `fdqn` value if `name` is a wildcard domain name (the leftmost label is `*`). This fixes a regression introduced in [v5.83.0](https://github.com/hashicorp/terraform-provider-aws/blob/main/CHANGELOG.md#5830-january--9-2025)
```
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 5.84.0 (Unreleased)
## 5.83.1 (Unreleased)
## 5.83.0 (January 9, 2025)

NOTES:
Expand Down
6 changes: 4 additions & 2 deletions internal/service/route53/clean_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,18 @@ func TestNormalizeAliasDomainName(t *testing.T) {
t.Parallel()

cases := []struct {
input, output string
input interface{}
output string
}{
{"www.example.com", "www.example.com"},
{"www.example.com.", "www.example.com"},
{"dualstack.name-123456789.region.elb.amazonaws.com", "dualstack.name-123456789.region.elb.amazonaws.com"},
{"dualstacktest.test", "dualstacktest.test"},
{aws.String("dualstacktest.test"), "dualstacktest.test"},
{"ipv6.name-123456789.region.elb.amazonaws.com", "ipv6.name-123456789.region.elb.amazonaws.com"},
{"NAME-123456789.region.elb.amazonaws.com", "name-123456789.region.elb.amazonaws.com"},
{"name-123456789.region.elb.amazonaws.com", "name-123456789.region.elb.amazonaws.com"},
{"\\052.example.com", "\\052.example.com"},
{42, ""},
}

for _, tc := range cases {
Expand Down
6 changes: 6 additions & 0 deletions internal/service/route53/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,12 @@ func resourceRecordRead(ctx context.Context, d *schema.ResourceData, meta interf
return sdkdiag.AppendErrorf(diags, "setting failover_routing_policy: %s", err)
}
}
// findResourceRecordSetByFourPartKey returns the FQDN in API-normalized form.
// For backwards compatibility, restore any '*' as the leftmost label in the domain name.
// \052 is the octal representation of '*'.
if v := aws.ToString(fqdn); strings.HasPrefix(v, `\052.`) {
fqdn = aws.String(`*.` + strings.TrimPrefix(v, `\052.`))
}
d.Set("fqdn", fqdn)
if geoLocation := record.GeoLocation; geoLocation != nil {
tfList := []interface{}{map[string]interface{}{
Expand Down
22 changes: 22 additions & 0 deletions internal/service/route53/record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import (
"github.com/hashicorp/aws-sdk-go-base/v2/endpoints"
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
"github.com/hashicorp/terraform-plugin-testing/plancheck"
"github.com/hashicorp/terraform-plugin-testing/statecheck"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
tfroute53 "github.com/hashicorp/terraform-provider-aws/internal/service/route53"
Expand Down Expand Up @@ -375,6 +379,15 @@ func TestAccRoute53Record_wildcard(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckRecordExists(ctx, resourceName, &record1),
),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate),
},
},
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("fqdn"), knownvalue.StringExact("*.domain.test")),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrName), knownvalue.StringExact("*.domain.test")),
},
},
{
ResourceName: resourceName,
Expand All @@ -389,6 +402,15 @@ func TestAccRoute53Record_wildcard(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckRecordExists(ctx, resourceName, &record2),
),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionUpdate),
},
},
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("fqdn"), knownvalue.StringExact("*.domain.test")),
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrName), knownvalue.StringExact("*.domain.test")),
},
},
},
})
Expand Down
Loading