@@ -512,3 +512,111 @@ resource "hetznerdns_record" "%s" {
512
512
}
513
513
}` , resourceName , name , recordType , value )
514
514
}
515
+
516
+ func TestAccRecord_UpdateResourceType (t * testing.T ) {
517
+ zoneName := acctest .RandString (10 ) + ".online"
518
+ aZoneTTL := 60
519
+
520
+ aName := acctest .RandString (10 )
521
+ oldType := "AAAA"
522
+ oldValue := "2001:4860:4860::8888"
523
+ newType := "A"
524
+ newValue := "1.1.1.1"
525
+ ttl := aZoneTTL * 2
526
+
527
+ resource .Test (t , resource.TestCase {
528
+ PreCheck : func () { testAccPreCheck (t ) },
529
+ ProtoV6ProviderFactories : testAccProtoV6ProviderFactories ,
530
+ Steps : []resource.TestStep {
531
+ // Create and Read testing
532
+ {
533
+ Config : strings .Join (
534
+ []string {
535
+ testAccZoneResourceConfig ("test" , zoneName , aZoneTTL ),
536
+ testAccRecordResourceConfigWithTTL ("record1" , aName , oldType , oldValue , ttl ),
537
+ }, "\n " ,
538
+ ),
539
+ Check : resource .ComposeTestCheckFunc (
540
+ resource .TestCheckResourceAttrSet (
541
+ "hetznerdns_record.record1" , "id" ),
542
+ resource .TestCheckResourceAttr (
543
+ "hetznerdns_record.record1" , "type" , oldType ),
544
+ resource .TestCheckResourceAttr (
545
+ "hetznerdns_record.record1" , "name" , aName ),
546
+ resource .TestCheckResourceAttr (
547
+ "hetznerdns_record.record1" , "value" , oldValue ),
548
+ resource .TestCheckResourceAttr (
549
+ "hetznerdns_record.record1" , "ttl" , strconv .Itoa (ttl )),
550
+ ),
551
+ },
552
+ // ImportState testing
553
+ {
554
+ ResourceName : "hetznerdns_record.record1" ,
555
+ ImportState : true ,
556
+ ImportStateVerify : true ,
557
+ },
558
+ // Update and Read testing
559
+ {
560
+ Config : strings .Join (
561
+ []string {
562
+ testAccZoneResourceConfig ("test" , zoneName , aZoneTTL ),
563
+ testAccRecordResourceConfigWithTTL ("record1" , aName , oldType , oldValue , ttl * 2 ),
564
+ }, "\n " ,
565
+ ),
566
+ Check : resource .ComposeAggregateTestCheckFunc (
567
+ resource .TestCheckResourceAttr (
568
+ "hetznerdns_record.record1" , "ttl" , strconv .Itoa (ttl * 2 )),
569
+ ),
570
+ },
571
+ // Update record type and value
572
+ {
573
+ Config : strings .Join (
574
+ []string {
575
+ testAccZoneResourceConfig ("test" , zoneName , aZoneTTL ),
576
+ testAccRecordResourceConfigWithTTL ("record1" , aName , newType , newValue , ttl * 2 ),
577
+ }, "\n " ,
578
+ ),
579
+ Check : resource .ComposeTestCheckFunc (
580
+ resource .TestCheckResourceAttrSet (
581
+ "hetznerdns_record.record1" , "id" ),
582
+ resource .TestCheckResourceAttr (
583
+ "hetznerdns_record.record1" , "type" , newType ),
584
+ resource .TestCheckResourceAttr (
585
+ "hetznerdns_record.record1" , "name" , aName ),
586
+ resource .TestCheckResourceAttr (
587
+ "hetznerdns_record.record1" , "value" , newValue ),
588
+ resource .TestCheckResourceAttr (
589
+ "hetznerdns_record.record1" , "ttl" , strconv .Itoa (ttl * 2 )),
590
+ ),
591
+ },
592
+ // ImportState testing
593
+ {
594
+ ResourceName : "hetznerdns_record.record1" ,
595
+ ImportState : true ,
596
+ ImportStateVerify : true ,
597
+ },
598
+ // Update and Read testing
599
+ {
600
+ Config : strings .Join (
601
+ []string {
602
+ testAccZoneResourceConfig ("test" , zoneName , aZoneTTL ),
603
+ testAccRecordResourceConfigWithTTL ("record1" , aName , newType , newValue , ttl * 2 ),
604
+ }, "\n " ,
605
+ ),
606
+ Check : resource .ComposeTestCheckFunc (
607
+ resource .TestCheckResourceAttrSet (
608
+ "hetznerdns_record.record1" , "id" ),
609
+ resource .TestCheckResourceAttr (
610
+ "hetznerdns_record.record1" , "type" , newType ),
611
+ resource .TestCheckResourceAttr (
612
+ "hetznerdns_record.record1" , "name" , aName ),
613
+ resource .TestCheckResourceAttr (
614
+ "hetznerdns_record.record1" , "value" , newValue ),
615
+ resource .TestCheckResourceAttr (
616
+ "hetznerdns_record.record1" , "ttl" , strconv .Itoa (ttl * 2 )),
617
+ ),
618
+ },
619
+ // Delete testing automatically occurs in TestCase
620
+ },
621
+ })
622
+ }
0 commit comments