From 54c47ca3c21351503c83c0e14f67bb7df4cd560d Mon Sep 17 00:00:00 2001 From: Alexandro Cortico Date: Tue, 15 Oct 2024 15:59:22 +0100 Subject: [PATCH 1/6] Update record.go allow ttl to be 0 Issue #36411 aws_route53_record fails when ttl is set to 0 --- internal/service/route53/record.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/route53/record.go b/internal/service/route53/record.go index aeef59b958c..be24ed47ce6 100644 --- a/internal/service/route53/record.go +++ b/internal/service/route53/record.go @@ -616,7 +616,7 @@ func resourceRecordUpdate(ctx context.Context, d *schema.ResourceData, meta inte } } - if v, _ := d.GetChange("ttl"); v.(int) != 0 { + if v, _ := d.GetChange("ttl"); v != nil { oldRec.TTL = aws.Int64(int64(v.(int))) } From 2997c7936eefd666c56c3e0803b84b0644eecbeb Mon Sep 17 00:00:00 2001 From: Alexandro Cortico Date: Tue, 15 Oct 2024 16:52:38 +0100 Subject: [PATCH 2/6] Create 39728.txt add changelog file --- .changelog/39728.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/39728.txt diff --git a/.changelog/39728.txt b/.changelog/39728.txt new file mode 100644 index 00000000000..011e57bf9db --- /dev/null +++ b/.changelog/39728.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_route53_record: Fix to allow creation of records witth ttl=0 +``` From 5ffeb3a488fdb8663d0ad66d1878aaae4cca1416 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 16 Oct 2024 11:31:07 -0400 Subject: [PATCH 3/6] Tweak CHANGELOG entry. --- .changelog/39728.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/39728.txt b/.changelog/39728.txt index 011e57bf9db..4358f04248b 100644 --- a/.changelog/39728.txt +++ b/.changelog/39728.txt @@ -1,3 +1,3 @@ ```release-note:bug -resource/aws_route53_record: Fix to allow creation of records witth ttl=0 +resource/aws_route53_record: Allow creation of records with `ttl=0` ``` From fdd012bd2c3dc3f8c84965b06242487b10384530 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 16 Oct 2024 11:37:06 -0400 Subject: [PATCH 4/6] Add 'TestAccRoute53Record_ttl0'. --- internal/service/route53/record_test.go | 60 +++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/internal/service/route53/record_test.go b/internal/service/route53/record_test.go index d562235f666..a660d1c30c4 100644 --- a/internal/service/route53/record_test.go +++ b/internal/service/route53/record_test.go @@ -1530,6 +1530,50 @@ func TestAccRoute53Record_Allow_overwrite(t *testing.T) { }) } +func TestAccRoute53Record_ttl0(t *testing.T) { + ctx := acctest.Context(t) + var v awstypes.ResourceRecordSet + resourceName := "aws_route53_record.test" + zoneName := acctest.RandomDomain() + recordName := zoneName.RandomSubdomain() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.Route53ServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckRecordDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccRecordConfig_ttl(zoneName.String(), strings.ToUpper(recordName.String()), 0), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckRecordExists(ctx, resourceName, &v), + resource.TestCheckResourceAttr(resourceName, "ttl", acctest.Ct0), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"allow_overwrite", names.AttrWeight}, + }, + { + Config: testAccRecordConfig_ttl(zoneName.String(), strings.ToUpper(recordName.String()), 45), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckRecordExists(ctx, resourceName, &v), + resource.TestCheckResourceAttr(resourceName, "ttl", "45"), + ), + }, + { + Config: testAccRecordConfig_ttl(zoneName.String(), strings.ToUpper(recordName.String()), 0), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckRecordExists(ctx, resourceName, &v), + resource.TestCheckResourceAttr(resourceName, "ttl", acctest.Ct0), + ), + }, + }, + }) +} + // testAccErrorCheckSkip skips Route53 tests that have error messages indicating unsupported features func testAccErrorCheckSkip(t *testing.T) resource.ErrorCheckFunc { return acctest.ErrorCheckSkipMessagesContaining(t, @@ -3195,3 +3239,19 @@ resource "aws_route53_record" "www-server1" { records = ["127.0.0.1"] } ` + +func testAccRecordConfig_ttl(zoneName, recordName string, ttl int) string { + return fmt.Sprintf(` +resource "aws_route53_zone" "test" { + name = %[1]q +} + +resource "aws_route53_record" "test" { + zone_id = aws_route53_zone.test.zone_id + name = %[2]q + type = "A" + ttl = %[3]d + records = ["127.0.0.1", "127.0.0.27"] +} +`, zoneName, recordName, ttl) +} From 11d2aeda3107dedbfa04d058d8ead6cef72e1dc9 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 16 Oct 2024 11:45:31 -0400 Subject: [PATCH 5/6] Fix 'expandResourceRecordSet' for 0 ttl. --- internal/service/route53/record.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/service/route53/record.go b/internal/service/route53/record.go index be24ed47ce6..5600e07bea4 100644 --- a/internal/service/route53/record.go +++ b/internal/service/route53/record.go @@ -904,8 +904,9 @@ func expandResourceRecordSet(d *schema.ResourceData, zoneName string) *awstypes. Type: rrType, } - if v, ok := d.GetOk("ttl"); ok { - apiObject.TTL = aws.Int64(int64(v.(int))) + if v := d.GetRawConfig().GetAttr("ttl"); v.IsKnown() && !v.IsNull() { + v, _ := v.AsBigFloat().Int64() + apiObject.TTL = aws.Int64(v) } // Resource records From 40700b949fe816b433f8b616c919441afe1cc8f7 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 16 Oct 2024 16:03:39 -0400 Subject: [PATCH 6/6] r/aws_route53_record: Only send TTL with ResourceRecords. --- internal/service/route53/record.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/internal/service/route53/record.go b/internal/service/route53/record.go index 5600e07bea4..e845687f067 100644 --- a/internal/service/route53/record.go +++ b/internal/service/route53/record.go @@ -616,14 +616,16 @@ func resourceRecordUpdate(ctx context.Context, d *schema.ResourceData, meta inte } } - if v, _ := d.GetChange("ttl"); v != nil { - oldRec.TTL = aws.Int64(int64(v.(int))) - } - // Resource records if v, _ := d.GetChange("records"); v != nil { if v.(*schema.Set).Len() > 0 { oldRec.ResourceRecords = expandResourceRecords(flex.ExpandStringValueSet(v.(*schema.Set)), awstypes.RRType(oldRRType.(string))) + + // TTL and ResourceRecords + if v := d.GetRawState().GetAttr("ttl"); !v.IsNull() { + v, _ := v.AsBigFloat().Int64() + oldRec.TTL = aws.Int64(v) + } } } @@ -904,14 +906,15 @@ func expandResourceRecordSet(d *schema.ResourceData, zoneName string) *awstypes. Type: rrType, } - if v := d.GetRawConfig().GetAttr("ttl"); v.IsKnown() && !v.IsNull() { - v, _ := v.AsBigFloat().Int64() - apiObject.TTL = aws.Int64(v) - } - // Resource records if v, ok := d.GetOk("records"); ok { apiObject.ResourceRecords = expandResourceRecords(flex.ExpandStringValueSet(v.(*schema.Set)), rrType) + + // TTL and ResourceRecords + if v := d.GetRawPlan().GetAttr("ttl"); v.IsKnown() && !v.IsNull() { + v, _ := v.AsBigFloat().Int64() + apiObject.TTL = aws.Int64(v) + } } // Alias record