diff --git a/CHANGELOG.md b/CHANGELOG.md index 569473f..ab73db5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.4.4 (October 10, 2024) +BUGFIX +* Adds support for setting override_address_records for ALIAS records + ## 2.4.3 (October 2, 2024) * Modified target regex for redirects to align with server diff --git a/ns1/config.go b/ns1/config.go index 97fde12..03b85db 100644 --- a/ns1/config.go +++ b/ns1/config.go @@ -19,7 +19,7 @@ import ( ) var ( - clientVersion = "2.4.3" + clientVersion = "2.4.4" providerUserAgent = "tf-ns1" + "/" + clientVersion defaultRetryMax = 3 ) diff --git a/ns1/data_source_record.go b/ns1/data_source_record.go index fdb8cfe..a33f635 100644 --- a/ns1/data_source_record.go +++ b/ns1/data_source_record.go @@ -23,6 +23,10 @@ func dataSourceRecord() *schema.Resource { Type: schema.TypeInt, Computed: true, }, + "override_address_records": { + Type: schema.TypeBool, + Computed: true, + }, "override_ttl": { Type: schema.TypeBool, Computed: true, diff --git a/ns1/resource_record.go b/ns1/resource_record.go index 042bb51..2376c78 100644 --- a/ns1/resource_record.go +++ b/ns1/resource_record.go @@ -75,6 +75,10 @@ func recordResource() *schema.Resource { Optional: true, Computed: true, }, + "override_address_records": { + Type: schema.TypeBool, + Optional: true, + }, "override_ttl": { Type: schema.TypeBool, Optional: true, @@ -242,10 +246,19 @@ func recordToResourceData(d *schema.ResourceData, r *dns.Record) error { d.Set("blocked_tags", terraformBlockedTags) } + if r.Type == "ALIAS" { + d.Set("override_address_records", false) + if r.OverrideAddressRecords != nil { + err := d.Set("override_address_records", *r.OverrideAddressRecords) + if err != nil { + return fmt.Errorf("[DEBUG] Error setting override_address_records for: %s, error: %#v", r.Domain, err) + } + } + } + d.Set("override_ttl", nil) if r.Type == "ALIAS" && r.OverrideTTL != nil { err := d.Set("override_ttl", *r.OverrideTTL) - if err != nil { return fmt.Errorf("[DEBUG] Error setting override_ttl for: %s, error: %#v", r.Domain, err) } @@ -407,6 +420,9 @@ func resourceDataToRecord(r *dns.Record, d *schema.ResourceData) error { } if r.Type == "ALIAS" { + Override_AddressRecords := d.Get("override_address_records").(bool) + r.OverrideAddressRecords = &Override_AddressRecords + Override_TTL := d.Get("override_ttl").(bool) r.OverrideTTL = &Override_TTL } diff --git a/ns1/resource_record_test.go b/ns1/resource_record_test.go index b6b0813..b1eb329 100644 --- a/ns1/resource_record_test.go +++ b/ns1/resource_record_test.go @@ -861,6 +861,153 @@ func TestAccRecord_OverrideTTLTrueToFalse(t *testing.T) { }) } +func TestAccRecord_OverrideAddressRecordsNilToTrue(t *testing.T) { + var record dns.Record + rString := acctest.RandStringFromCharSet(15, acctest.CharSetAlphaNum) + + tfFileBasicAlias := testAccRecordBasicALIAS(rString) + tfFileOverrideAddressRecordsAliasTrue := testAccRecordBasicALIASOverrideAddressRecords(rString, true) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckRecordDestroy, + Steps: []resource.TestStep{ + // Create an ALIAS record with override_address_records not set + { + Config: tfFileBasicAlias, + Check: resource.ComposeTestCheckFunc( + testAccCheckRecordExists("ns1_record.it", &record), + testAccCheckRecordOverrideAddressRecords(&record, false), + ), + }, + // Plan again to detect "loop" conditions + { + Config: tfFileBasicAlias, + PlanOnly: true, + ExpectNonEmptyPlan: false, + }, + // Change override_address_records to true Plan and Apply + { + Config: tfFileOverrideAddressRecordsAliasTrue, + PlanOnly: true, + ExpectNonEmptyPlan: true, + }, + { + Config: tfFileOverrideAddressRecordsAliasTrue, + Check: resource.ComposeTestCheckFunc( + testAccCheckRecordExists("ns1_record.it", &record), + testAccCheckRecordOverrideAddressRecords(&record, true), + ), + }, + // Plan again to detect "loop" conditions + { + Config: tfFileOverrideAddressRecordsAliasTrue, + PlanOnly: true, + ExpectNonEmptyPlan: false, + }, + }, + }) +} + +func TestAccRecord_OverrideAddressRecordsTrueToNil(t *testing.T) { + var record dns.Record + rString := acctest.RandStringFromCharSet(15, acctest.CharSetAlphaNum) + + tfFileBasicAlias := testAccRecordBasicALIAS(rString) + tfFileOverrideAddressRecordsAliasTrue := testAccRecordBasicALIASOverrideAddressRecords(rString, true) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckRecordDestroy, + Steps: []resource.TestStep{ + // Create an ALIAS record with override_address_records true + { + Config: tfFileOverrideAddressRecordsAliasTrue, + Check: resource.ComposeTestCheckFunc( + testAccCheckRecordExists("ns1_record.it", &record), + testAccCheckRecordOverrideAddressRecords(&record, true), + ), + }, + // Plan again to detect "loop" conditions + { + Config: tfFileOverrideAddressRecordsAliasTrue, + PlanOnly: true, + ExpectNonEmptyPlan: false, + }, + { + Config: tfFileBasicAlias, + PlanOnly: true, + ExpectNonEmptyPlan: true, + }, + // Change override_address_records from true setting to "null" results in false + { + Config: tfFileBasicAlias, + Check: resource.ComposeTestCheckFunc( + testAccCheckRecordExists("ns1_record.it", &record), + testAccCheckRecordOverrideAddressRecords(&record, false), + ), + }, + // Plan again to detect "loop" conditions + { + Config: tfFileBasicAlias, + PlanOnly: true, + ExpectNonEmptyPlan: false, + }, + }, + }) +} + +func TestAccRecord_OverrideAddressRecordsTrueToFalse(t *testing.T) { + var record dns.Record + rString := acctest.RandStringFromCharSet(15, acctest.CharSetAlphaNum) + + tfFileOverrideAddressRecordsAliasTrue := testAccRecordBasicALIASOverrideAddressRecords(rString, true) + tfFileDoNotOverrideAddressRecordsAliasFalse := testAccRecordBasicALIASOverrideAddressRecords(rString, false) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckRecordDestroy, + Steps: []resource.TestStep{ + // Create an ALIAS record with override_address_records true + { + Config: tfFileOverrideAddressRecordsAliasTrue, + Check: resource.ComposeTestCheckFunc( + testAccCheckRecordExists("ns1_record.it", &record), + testAccCheckRecordOverrideAddressRecords(&record, true), + ), + }, + // Plan again to detect "loop" conditions + { + Config: tfFileOverrideAddressRecordsAliasTrue, + PlanOnly: true, + ExpectNonEmptyPlan: false, + }, + // Change override_address_records to false setting to false Plan and Apply + { + Config: tfFileDoNotOverrideAddressRecordsAliasFalse, + ExpectNonEmptyPlan: true, + PlanOnly: true, + }, + { + Config: tfFileDoNotOverrideAddressRecordsAliasFalse, + Check: resource.ComposeTestCheckFunc( + testAccCheckRecordExists("ns1_record.it", &record), + testAccCheckRecordOverrideAddressRecords(&record, false), + ), + }, + // Plan again to detect "loop" conditions + { + Config: tfFileDoNotOverrideAddressRecordsAliasFalse, + PlanOnly: true, + ExpectNonEmptyPlan: false, + }, + }, + }) +} + func TestAccRecord_Link(t *testing.T) { var record1 dns.Record var record2 dns.Record @@ -1049,6 +1196,16 @@ func ExpectOverrideTTLNotNil() bool { return false } +func testAccCheckRecordOverrideAddressRecords(r *dns.Record, expected bool) resource.TestCheckFunc { + return func(s *terraform.State) error { + if *r.OverrideAddressRecords != expected { + return fmt.Errorf("Override Address Records: got: %#v want: %#v", *r.OverrideAddressRecords, expected) + } + + return nil + } +} + func testAccCheckRecordOverrideTTL(r *dns.Record, expectedNil bool) resource.TestCheckFunc { return func(s *terraform.State) error { if expectedNil { @@ -1273,6 +1430,25 @@ resource "ns1_zone" "test" { `, domain, zone) } +func testAccRecordBasicALIASOverrideAddressRecords(rString string, overrideAddressRecords bool) string { + return fmt.Sprintf(` +resource "ns1_record" "it" { + zone = "${ns1_zone.test.zone}" + domain = "${ns1_zone.test.zone}" + type = "ALIAS" + ttl = 60 + override_address_records = %v + answers { + answer = "test.${ns1_zone.test.zone}" + } +} + +resource "ns1_zone" "test" { + zone = "terraform-test-%s.io" +} +`, overrideAddressRecords, rString) +} + func testAccRecordBasicALIASOverrideTTL(rString string, overridettl bool) string { return fmt.Sprintf(` resource "ns1_record" "it" {