@@ -29,7 +29,7 @@ func TestAccPDNSRecord_Empty(t *testing.T) {
29
29
}
30
30
31
31
func TestAccPDNSRecord_A (t * testing.T ) {
32
- testPDNSRecordCommonTestCore (t , testPDNSRecordConfigA () )
32
+ testPDNSRecordCommonTestCore (t , testPDNSRecordConfigA )
33
33
}
34
34
35
35
func TestAccPDNSRecord_WithPtr (t * testing.T ) {
@@ -92,59 +92,59 @@ func TestAccPDNSRecord_WithCount(t *testing.T) {
92
92
}
93
93
94
94
func TestAccPDNSRecord_AAAA (t * testing.T ) {
95
- testPDNSRecordCommonTestCore (t , testPDNSRecordConfigAAAA () )
95
+ testPDNSRecordCommonTestCore (t , testPDNSRecordConfigAAAA )
96
96
}
97
97
98
98
func TestAccPDNSRecord_CNAME (t * testing.T ) {
99
- testPDNSRecordCommonTestCore (t , testPDNSRecordConfigCNAME () )
99
+ testPDNSRecordCommonTestCore (t , testPDNSRecordConfigCNAME )
100
100
}
101
101
102
102
func TestAccPDNSRecord_HINFO (t * testing.T ) {
103
- testPDNSRecordCommonTestCore (t , testPDNSRecordConfigHINFO () )
103
+ testPDNSRecordCommonTestCore (t , testPDNSRecordConfigHINFO )
104
104
}
105
105
106
106
func TestAccPDNSRecord_LOC (t * testing.T ) {
107
- testPDNSRecordCommonTestCore (t , testPDNSRecordConfigLOC () )
107
+ testPDNSRecordCommonTestCore (t , testPDNSRecordConfigLOC )
108
108
}
109
109
110
110
func TestAccPDNSRecord_MX (t * testing.T ) {
111
- testPDNSRecordCommonTestCore (t , testPDNSRecordConfigMX () )
111
+ testPDNSRecordCommonTestCore (t , testPDNSRecordConfigMX )
112
112
}
113
113
114
114
func TestAccPDNSRecord_MXMulti (t * testing.T ) {
115
- testPDNSRecordCommonTestCore (t , testPDNSRecordConfigMXMulti () )
115
+ testPDNSRecordCommonTestCore (t , testPDNSRecordConfigMXMulti )
116
116
}
117
117
118
118
func TestAccPDNSRecord_NAPTR (t * testing.T ) {
119
- testPDNSRecordCommonTestCore (t , testPDNSRecordConfigNAPTR () )
119
+ testPDNSRecordCommonTestCore (t , testPDNSRecordConfigNAPTR )
120
120
}
121
121
122
122
func TestAccPDNSRecord_NS (t * testing.T ) {
123
- testPDNSRecordCommonTestCore (t , testPDNSRecordConfigNS () )
123
+ testPDNSRecordCommonTestCore (t , testPDNSRecordConfigNS )
124
124
}
125
125
126
126
func TestAccPDNSRecord_SPF (t * testing.T ) {
127
- testPDNSRecordCommonTestCore (t , testPDNSRecordConfigSPF () )
127
+ testPDNSRecordCommonTestCore (t , testPDNSRecordConfigSPF )
128
128
}
129
129
130
130
func TestAccPDNSRecord_SSHFP (t * testing.T ) {
131
- testPDNSRecordCommonTestCore (t , testPDNSRecordConfigSSHFP () )
131
+ testPDNSRecordCommonTestCore (t , testPDNSRecordConfigSSHFP )
132
132
}
133
133
134
134
func TestAccPDNSRecord_SRV (t * testing.T ) {
135
- testPDNSRecordCommonTestCore (t , testPDNSRecordConfigSRV () )
135
+ testPDNSRecordCommonTestCore (t , testPDNSRecordConfigSRV )
136
136
}
137
137
138
138
func TestAccPDNSRecord_TXT (t * testing.T ) {
139
- testPDNSRecordCommonTestCore (t , testPDNSRecordConfigTXT () )
139
+ testPDNSRecordCommonTestCore (t , testPDNSRecordConfigTXT )
140
140
}
141
141
142
142
func TestAccPDNSRecord_ALIAS (t * testing.T ) {
143
- testPDNSRecordCommonTestCore (t , testPDNSRecordConfigALIAS () )
143
+ testPDNSRecordCommonTestCore (t , testPDNSRecordConfigALIAS )
144
144
}
145
145
146
146
func TestAccPDNSRecord_SOA (t * testing.T ) {
147
- testPDNSRecordCommonTestCore (t , testPDNSRecordConfigSOA () )
147
+ testPDNSRecordCommonTestCore (t , testPDNSRecordConfigSOA )
148
148
}
149
149
150
150
//
@@ -161,7 +161,9 @@ type PowerDNSRecordResourceArguments struct {
161
161
Type string
162
162
TTL int
163
163
Records []string
164
- SetPtr bool
164
+ // UpdateRecords are recordsets used for testing update behavior.
165
+ UpdateRecords []string
166
+ SetPtr bool
165
167
}
166
168
167
169
type PowerDNSRecordResource struct {
@@ -207,16 +209,45 @@ func (resourceConfig *PowerDNSRecordResource) ResourceID() string {
207
209
//
208
210
// Test Helper Functions
209
211
//
210
- func testPDNSRecordCommonTestCore (t * testing.T , recordConfig * PowerDNSRecordResource ) {
212
+
213
+ // Common Test Core: This function builds a create / update test for the majority of test cases
214
+ // Takes a function variable to avoid deep copy issues on updates.
215
+ func testPDNSRecordCommonTestCore (t * testing.T , recordConfigGenerator func () * PowerDNSRecordResource ) {
216
+ // Update test resources.
217
+ recordConfig := recordConfigGenerator ()
218
+
219
+ ttlUpdateRecordConfig := recordConfigGenerator ()
220
+ ttlUpdateRecordConfig .Arguments .TTL += 100
221
+
222
+ recordUpdateRecordConfig := recordConfigGenerator ()
223
+ recordUpdateRecordConfig .Arguments .Records = recordUpdateRecordConfig .Arguments .UpdateRecords
224
+
211
225
resource .ParallelTest (t , resource.TestCase {
212
226
PreCheck : func () { testAccPreCheck (t ) },
213
227
Providers : testAccProviders ,
214
228
CheckDestroy : testAccCheckPDNSRecordDestroy ,
215
229
Steps : []resource.TestStep {
230
+ // Initial record creation
216
231
{
217
232
Config : recordConfig .ResourceDeclaration (),
218
233
Check : resource .ComposeTestCheckFunc (
219
234
testAccCheckPDNSRecordContents (recordConfig ),
235
+ // TestCheckResourceAttr() checks are skipped because records is not directly accessible
236
+ // https://github.com/hashicorp/terraform/issues/21618
237
+ ),
238
+ },
239
+ // TTL update
240
+ {
241
+ Config : ttlUpdateRecordConfig .ResourceDeclaration (),
242
+ Check : resource .ComposeTestCheckFunc (
243
+ testAccCheckPDNSRecordContents (ttlUpdateRecordConfig ),
244
+ ),
245
+ },
246
+ // Records update
247
+ {
248
+ Config : recordUpdateRecordConfig .ResourceDeclaration (),
249
+ Check : resource .ComposeTestCheckFunc (
250
+ testAccCheckPDNSRecordContents (recordUpdateRecordConfig ),
220
251
),
221
252
},
222
253
{
@@ -370,6 +401,9 @@ func testPDNSRecordConfigA() *PowerDNSRecordResource {
370
401
record .Arguments .Type = "A"
371
402
record .Arguments .Records = append (record .Arguments .Records , "1.1.1.1" )
372
403
record .Arguments .Records = append (record .Arguments .Records , "2.2.2.2" )
404
+
405
+ record .Arguments .UpdateRecords = append (record .Arguments .UpdateRecords , "2.2.2.2" )
406
+ record .Arguments .UpdateRecords = append (record .Arguments .UpdateRecords , "3.3.3.3" )
373
407
return record
374
408
}
375
409
@@ -379,6 +413,7 @@ func testPDNSRecordConfigAWithPtr() *PowerDNSRecordResource {
379
413
record .Arguments .Name = "testpdnsrecordconfigrecordawithptr.sysa.xyz."
380
414
record .Arguments .Type = "A"
381
415
record .Arguments .Records = append (record .Arguments .Records , "1.1.1.1" )
416
+ record .Arguments .UpdateRecords = append (record .Arguments .UpdateRecords , "2.2.2.2" )
382
417
record .Arguments .SetPtr = true
383
418
return record
384
419
}
@@ -400,6 +435,8 @@ func testPDNSRecordConfigAAAA() *PowerDNSRecordResource {
400
435
record .Arguments .Type = "AAAA"
401
436
record .Arguments .Records = append (record .Arguments .Records , "2001:db8:2000:bf0::1" )
402
437
record .Arguments .Records = append (record .Arguments .Records , "2001:db8:2000:bf1::1" )
438
+ record .Arguments .UpdateRecords = append (record .Arguments .UpdateRecords , "2001:db8:2000:bf3::1" )
439
+ record .Arguments .UpdateRecords = append (record .Arguments .UpdateRecords , "2001:db8:2000:bf4::1" )
403
440
return record
404
441
}
405
442
@@ -409,6 +446,7 @@ func testPDNSRecordConfigCNAME() *PowerDNSRecordResource {
409
446
record .Arguments .Name = "testpdnsrecordconfigcname.sysa.xyz."
410
447
record .Arguments .Type = "CNAME"
411
448
record .Arguments .Records = append (record .Arguments .Records , "redis.example.com." )
449
+ record .Arguments .UpdateRecords = append (record .Arguments .UpdateRecords , "redis.example.net." )
412
450
return record
413
451
}
414
452
@@ -418,6 +456,7 @@ func testPDNSRecordConfigHINFO() *PowerDNSRecordResource {
418
456
record .Arguments .Name = "testpdnsrecordconfighinfo.sysa.xyz."
419
457
record .Arguments .Type = "HINFO"
420
458
record .Arguments .Records = append (record .Arguments .Records , `"PC-Intel-2.4ghz" "Linux"` )
459
+ record .Arguments .UpdateRecords = append (record .Arguments .UpdateRecords , `"PC-Intel-3.2ghz" "Linux"` )
421
460
return record
422
461
}
423
462
@@ -427,6 +466,7 @@ func testPDNSRecordConfigLOC() *PowerDNSRecordResource {
427
466
record .Arguments .Name = "testpdnsrecordconfigloc.sysa.xyz."
428
467
record .Arguments .Type = "LOC"
429
468
record .Arguments .Records = append (record .Arguments .Records , "51 56 0.123 N 5 54 0.000 E 4.00m 1.00m 10000.00m 10.00m" )
469
+ record .Arguments .UpdateRecords = append (record .Arguments .UpdateRecords , "51 10 43.900 N 1 49 34.300 E 4.00m 1.00m 10000.00m 10.00m" )
430
470
return record
431
471
}
432
472
@@ -436,6 +476,7 @@ func testPDNSRecordConfigMX() *PowerDNSRecordResource {
436
476
record .Arguments .Name = "sysa.xyz."
437
477
record .Arguments .Type = "MX"
438
478
record .Arguments .Records = append (record .Arguments .Records , "10 mail.example.com." )
479
+ record .Arguments .UpdateRecords = append (record .Arguments .UpdateRecords , "10 mail2.example.net." )
439
480
return record
440
481
}
441
482
@@ -446,6 +487,8 @@ func testPDNSRecordConfigMXMulti() *PowerDNSRecordResource {
446
487
record .Arguments .Type = "MX"
447
488
record .Arguments .Records = append (record .Arguments .Records , "10 mail.example.com." )
448
489
record .Arguments .Records = append (record .Arguments .Records , "20 mail2.example.com." )
490
+ record .Arguments .UpdateRecords = append (record .Arguments .UpdateRecords , "10 mail3.example.com." )
491
+ record .Arguments .UpdateRecords = append (record .Arguments .UpdateRecords , "10 mail4.example.com." )
449
492
return record
450
493
}
451
494
@@ -455,6 +498,7 @@ func testPDNSRecordConfigNAPTR() *PowerDNSRecordResource {
455
498
record .Arguments .Name = "sysa.xyz."
456
499
record .Arguments .Type = "NAPTR"
457
500
record .Arguments .Records = append (record .Arguments .Records , `100 50 "s" "z3950+I2L+I2C" "" _z3950._tcp.gatech.edu'.` )
501
+ record .Arguments .UpdateRecords = append (record .Arguments .UpdateRecords , `100 70 "s" "z3950+I2L+I2C" "" _z3950._tcp.gatech.edu'.` )
458
502
return record
459
503
}
460
504
@@ -465,6 +509,8 @@ func testPDNSRecordConfigNS() *PowerDNSRecordResource {
465
509
record .Arguments .Type = "NS"
466
510
record .Arguments .Records = append (record .Arguments .Records , "ns1.sysa.xyz." )
467
511
record .Arguments .Records = append (record .Arguments .Records , "ns2.sysa.xyz." )
512
+ record .Arguments .UpdateRecords = append (record .Arguments .UpdateRecords , "ns3.sysa.xyz." )
513
+ record .Arguments .UpdateRecords = append (record .Arguments .UpdateRecords , "ns4.sysa.xyz." )
468
514
return record
469
515
}
470
516
@@ -474,6 +520,7 @@ func testPDNSRecordConfigSPF() *PowerDNSRecordResource {
474
520
record .Arguments .Name = "sysa.xyz."
475
521
record .Arguments .Type = "SPF"
476
522
record .Arguments .Records = append (record .Arguments .Records , `"v=spf1 +all"` )
523
+ record .Arguments .UpdateRecords = append (record .Arguments .UpdateRecords , `"v=spf1 -all"` )
477
524
return record
478
525
}
479
526
@@ -483,6 +530,7 @@ func testPDNSRecordConfigSSHFP() *PowerDNSRecordResource {
483
530
record .Arguments .Name = "ssh.sysa.xyz."
484
531
record .Arguments .Type = "SSHFP"
485
532
record .Arguments .Records = append (record .Arguments .Records , "1 1 123456789abcdef67890123456789abcdef67890" )
533
+ record .Arguments .UpdateRecords = append (record .Arguments .UpdateRecords , "1 1 fedcba9876543210fedcba9876543210fedcba98" )
486
534
return record
487
535
}
488
536
@@ -494,6 +542,11 @@ func testPDNSRecordConfigSRV() *PowerDNSRecordResource {
494
542
record .Arguments .Records = append (record .Arguments .Records , "0 10 6379 redis1.sysa.xyz." )
495
543
record .Arguments .Records = append (record .Arguments .Records , "0 10 6379 redis2.sysa.xyz." )
496
544
record .Arguments .Records = append (record .Arguments .Records , "10 10 6379 redis-replica.sysa.xyz." )
545
+
546
+ record .Arguments .UpdateRecords = append (record .Arguments .UpdateRecords , "0 10 6379 redis1.sysa.xyz." )
547
+ record .Arguments .UpdateRecords = append (record .Arguments .UpdateRecords , "0 10 6379 redis2.sysa.xyz." )
548
+ record .Arguments .UpdateRecords = append (record .Arguments .UpdateRecords , "0 10 6379 redis3.sysa.xyz." )
549
+ record .Arguments .UpdateRecords = append (record .Arguments .UpdateRecords , "10 10 6379 redis-replica.sysa.xyz." )
497
550
return record
498
551
}
499
552
@@ -503,6 +556,7 @@ func testPDNSRecordConfigTXT() *PowerDNSRecordResource {
503
556
record .Arguments .Name = "text.sysa.xyz."
504
557
record .Arguments .Type = "TXT"
505
558
record .Arguments .Records = append (record .Arguments .Records , `"text record payload"` )
559
+ record .Arguments .UpdateRecords = append (record .Arguments .UpdateRecords , `"updated text record payload"` )
506
560
return record
507
561
}
508
562
@@ -513,6 +567,7 @@ func testPDNSRecordConfigALIAS() *PowerDNSRecordResource {
513
567
record .Arguments .Type = "ALIAS"
514
568
record .Arguments .TTL = 3600
515
569
record .Arguments .Records = append (record .Arguments .Records , "www.some-alias.com." )
570
+ record .Arguments .UpdateRecords = append (record .Arguments .UpdateRecords , "www.some-other-alias.com." )
516
571
return record
517
572
}
518
573
@@ -524,5 +579,6 @@ func testPDNSRecordConfigSOA() *PowerDNSRecordResource {
524
579
record .Arguments .Type = "SOA"
525
580
record .Arguments .TTL = 3600
526
581
record .Arguments .Records = append (record .Arguments .Records , "something.something. hostmaster.sysa.xyz. 2019090301 10800 3600 604800 3600" )
582
+ record .Arguments .UpdateRecords = append (record .Arguments .UpdateRecords , "something.something. hostmaster.sysa.xyz. 2021021801 10800 3600 604800 3600" )
527
583
return record
528
584
}
0 commit comments