@@ -106,6 +106,41 @@ func TestAccRecord_updated(t *testing.T) {
106106 })
107107}
108108
109+ func TestAccRecord_remove_all_filters (t * testing.T ) {
110+ var record dns.Record
111+ rString := acctest .RandStringFromCharSet (15 , acctest .CharSetAlphaNum )
112+ zoneName := fmt .Sprintf ("terraform-test-%s.io" , rString )
113+ domainName := fmt .Sprintf ("test.%s" , zoneName )
114+
115+ resource .Test (t , resource.TestCase {
116+ PreCheck : func () { testAccPreCheck (t ) },
117+ Providers : testAccProviders ,
118+ CheckDestroy : testAccCheckRecordDestroy ,
119+ Steps : []resource.TestStep {
120+ {
121+ Config : testAccRecordBasic (rString ),
122+ Check : resource .ComposeTestCheckFunc (
123+ testAccCheckRecordExists ("ns1_record.it" , & record ),
124+ testAccCheckRecordFilterCount (& record , 3 ),
125+ ),
126+ },
127+ {
128+ Config : testAccRecordUpdatedNoFilters (rString ),
129+ Check : resource .ComposeTestCheckFunc (
130+ testAccCheckRecordExists ("ns1_record.it" , & record ),
131+ testAccCheckRecordFilterCount (& record , 0 ),
132+ ),
133+ },
134+ {
135+ ResourceName : "ns1_record.it" ,
136+ ImportState : true ,
137+ ImportStateId : fmt .Sprintf ("%s/%s/CNAME" , zoneName , domainName ),
138+ ImportStateVerify : true ,
139+ },
140+ },
141+ })
142+ }
143+
109144func TestAccRecord_meta (t * testing.T ) {
110145 var record dns.Record
111146 rString := acctest .RandStringFromCharSet (15 , acctest .CharSetAlphaNum )
@@ -820,6 +855,16 @@ func testAccCheckRecordExists(n string, record *dns.Record) resource.TestCheckFu
820855 }
821856}
822857
858+ func testAccCheckRecordFilterCount (r * dns.Record , expected int ) resource.TestCheckFunc {
859+ return func (s * terraform.State ) error {
860+ if len (r .Filters ) != expected {
861+ return fmt .Errorf ("r.Filters, got: %d, want: %d" , len (r .Filters ), expected )
862+ }
863+
864+ return nil
865+ }
866+ }
867+
823868func testAccCheckRecordDestroy (s * terraform.State ) error {
824869 client := testAccProvider .Meta ().(* ns1.Client )
825870
@@ -1212,6 +1257,30 @@ resource "ns1_zone" "test" {
12121257` , rString )
12131258}
12141259
1260+ func testAccRecordUpdatedNoFilters (rString string ) string {
1261+ return fmt .Sprintf (`
1262+ resource "ns1_record" "it" {
1263+ zone = "${ns1_zone.test.zone}"
1264+ domain = "test.${ns1_zone.test.zone}"
1265+ type = "CNAME"
1266+ ttl = 60
1267+
1268+ answers {
1269+ answer = "test1.${ns1_zone.test.zone}"
1270+ region = "cal"
1271+ }
1272+
1273+ regions {
1274+ name = "cal"
1275+ }
1276+ }
1277+
1278+ resource "ns1_zone" "test" {
1279+ zone = "terraform-test-%s.io"
1280+ }
1281+ ` , rString )
1282+ }
1283+
12151284func testAccRecordAnswerMeta (rString string ) string {
12161285 return fmt .Sprintf (`
12171286resource "ns1_record" "it" {
0 commit comments