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