Skip to content

Commit

Permalink
Merge pull request #39728 from cortico-aws/b-aws_route53_record-ttl
Browse files Browse the repository at this point in the history
Update record.go allow ttl to be 0
  • Loading branch information
ewbankkit authored Oct 16, 2024
2 parents 34ed8e2 + 40700b9 commit b10bffc
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .changelog/39728.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_route53_record: Allow creation of records with `ttl=0`
```
20 changes: 12 additions & 8 deletions internal/service/route53/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,14 +616,16 @@ func resourceRecordUpdate(ctx context.Context, d *schema.ResourceData, meta inte
}
}

if v, _ := d.GetChange("ttl"); v.(int) != 0 {
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)
}
}
}

Expand Down Expand Up @@ -904,13 +906,15 @@ func expandResourceRecordSet(d *schema.ResourceData, zoneName string) *awstypes.
Type: rrType,
}

if v, ok := d.GetOk("ttl"); ok {
apiObject.TTL = aws.Int64(int64(v.(int)))
}

// 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
Expand Down
60 changes: 60 additions & 0 deletions internal/service/route53/record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}

0 comments on commit b10bffc

Please sign in to comment.