@@ -417,10 +417,12 @@ func resourceDomainsRegistrationCreate(ctx context.Context, d *schema.ResourceDa
417
417
registrarAPI := NewRegistrarDomainAPI (m )
418
418
419
419
projectID := d .Get ("project_id" ).(string )
420
+
420
421
domainNames := make ([]string , 0 )
421
422
for _ , v := range d .Get ("domain_names" ).([]interface {}) {
422
423
domainNames = append (domainNames , v .(string ))
423
424
}
425
+
424
426
durationInYears := uint32 (d .Get ("duration_in_years" ).(int ))
425
427
426
428
buyDomainsRequest := & domain.RegistrarAPIBuyDomainsRequest {
@@ -430,6 +432,7 @@ func resourceDomainsRegistrationCreate(ctx context.Context, d *schema.ResourceDa
430
432
}
431
433
432
434
ownerContactID := d .Get ("owner_contact_id" ).(string )
435
+
433
436
if ownerContactID != "" {
434
437
buyDomainsRequest .OwnerContactID = & ownerContactID
435
438
} else if ownerContacts , ok := d .GetOk ("owner_contact" ); ok {
@@ -469,20 +472,25 @@ func resourceDomainsRegistrationsRead(ctx context.Context, d *schema.ResourceDat
469
472
if err != nil {
470
473
return diag .FromErr (err )
471
474
}
475
+
472
476
if len (domainNames ) == 0 {
473
477
d .SetId ("" )
478
+
474
479
return nil
475
480
}
476
481
477
482
firstDomain := domainNames [0 ]
483
+
478
484
firstResp , err := registrarAPI .GetDomain (& domain.RegistrarAPIGetDomainRequest {
479
485
Domain : firstDomain ,
480
486
}, scw .WithContext (ctx ))
481
487
if err != nil {
482
488
if httperrors .Is404 (err ) {
483
489
d .SetId ("" )
490
+
484
491
return nil
485
492
}
493
+
486
494
return diag .FromErr (err )
487
495
}
488
496
@@ -501,7 +509,6 @@ func resourceDomainsRegistrationsRead(ctx context.Context, d *schema.ResourceDat
501
509
}
502
510
503
511
computedDnssec := false
504
-
505
512
if firstResp .Dnssec .Status == domain .DomainFeatureStatusEnabled {
506
513
computedDnssec = true
507
514
}
@@ -536,17 +543,16 @@ func resourceDomainsRegistrationUpdate(ctx context.Context, d *schema.ResourceDa
536
543
if err != nil {
537
544
return diag .FromErr (err )
538
545
}
546
+
539
547
if len (domainNames ) == 0 {
540
548
d .SetId ("" )
541
- return nil
542
- }
543
549
544
- if d .HasChange ("owner_contact_id" ) || d .HasChange ("owner_contact" ) {
545
- return diag .FromErr (fmt .Errorf ("the domain ownership transfer feature is not implemented in this provider because it requires manual validation through email notifications. This action can only be performed via the Scaleway Console" ))
550
+ return nil
546
551
}
547
552
548
553
if d .HasChange ("auto_renew" ) {
549
554
newAutoRenew := d .Get ("auto_renew" ).(bool )
555
+
550
556
for _ , domainName := range domainNames {
551
557
domainResp , err := registrarAPI .GetDomain (& domain.RegistrarAPIGetDomainRequest {
552
558
Domain : domainName ,
@@ -556,7 +562,8 @@ func resourceDomainsRegistrationUpdate(ctx context.Context, d *schema.ResourceDa
556
562
}
557
563
558
564
if newAutoRenew {
559
- if domainResp .AutoRenewStatus != domain .DomainFeatureStatusEnabled && domainResp .AutoRenewStatus != domain .DomainFeatureStatusEnabling {
565
+ if domainResp .AutoRenewStatus != domain .DomainFeatureStatusEnabled &&
566
+ domainResp .AutoRenewStatus != domain .DomainFeatureStatusEnabling {
560
567
_ , err = registrarAPI .EnableDomainAutoRenew (& domain.RegistrarAPIEnableDomainAutoRenewRequest {
561
568
Domain : domainName ,
562
569
}, scw .WithContext (ctx ))
@@ -565,7 +572,8 @@ func resourceDomainsRegistrationUpdate(ctx context.Context, d *schema.ResourceDa
565
572
}
566
573
}
567
574
} else {
568
- if domainResp .AutoRenewStatus == domain .DomainFeatureStatusEnabled || domainResp .AutoRenewStatus == domain .DomainFeatureStatusEnabling {
575
+ if domainResp .AutoRenewStatus == domain .DomainFeatureStatusEnabled ||
576
+ domainResp .AutoRenewStatus == domain .DomainFeatureStatusEnabling {
569
577
_ , err = registrarAPI .DisableDomainAutoRenew (& domain.RegistrarAPIDisableDomainAutoRenewRequest {
570
578
Domain : domainName ,
571
579
}, scw .WithContext (ctx ))
@@ -574,6 +582,7 @@ func resourceDomainsRegistrationUpdate(ctx context.Context, d *schema.ResourceDa
574
582
}
575
583
}
576
584
}
585
+
577
586
_ , err = waitForAutoRenewStatus (ctx , registrarAPI , domainName , d .Timeout (schema .TimeoutUpdate ))
578
587
if err != nil {
579
588
return diag .FromErr (err )
@@ -583,6 +592,7 @@ func resourceDomainsRegistrationUpdate(ctx context.Context, d *schema.ResourceDa
583
592
584
593
if d .HasChange ("dnssec" ) {
585
594
newDnssec := d .Get ("dnssec" ).(bool )
595
+
586
596
for _ , domainName := range domainNames {
587
597
domainResp , err := registrarAPI .GetDomain (& domain.RegistrarAPIGetDomainRequest {
588
598
Domain : domainName ,
@@ -593,27 +603,31 @@ func resourceDomainsRegistrationUpdate(ctx context.Context, d *schema.ResourceDa
593
603
594
604
if newDnssec {
595
605
var dsRecord * domain.DSRecord
606
+
596
607
if v , ok := d .GetOk ("ds_record" ); ok {
597
608
dsRecordList := v .([]interface {})
598
609
if len (dsRecordList ) > 0 && dsRecordList [0 ] != nil {
599
610
dsRecord = ExpandDSRecord (dsRecordList )
600
611
}
601
612
}
613
+
602
614
_ , err = registrarAPI .EnableDomainDNSSEC (& domain.RegistrarAPIEnableDomainDNSSECRequest {
603
615
Domain : domainName ,
604
616
DsRecord : dsRecord ,
605
617
}, scw .WithContext (ctx ))
606
618
if err != nil {
607
619
return diag .FromErr (fmt .Errorf ("failed to enable dnssec for %s: %w" , domainName , err ))
608
620
}
609
- } else if domainResp .Dnssec != nil && domainResp .Dnssec .Status == domain .DomainFeatureStatusEnabled {
621
+ } else if domainResp .Dnssec != nil &&
622
+ domainResp .Dnssec .Status == domain .DomainFeatureStatusEnabled {
610
623
_ , err = registrarAPI .DisableDomainDNSSEC (& domain.RegistrarAPIDisableDomainDNSSECRequest {
611
624
Domain : domainName ,
612
625
}, scw .WithContext (ctx ))
613
626
if err != nil {
614
627
return diag .FromErr (fmt .Errorf ("failed to disable dnssec for %s: %w" , domainName , err ))
615
628
}
616
629
}
630
+
617
631
_ , err = waitForDNSSECStatus (ctx , registrarAPI , domainName , d .Timeout (schema .TimeoutUpdate ))
618
632
if err != nil {
619
633
return diag .FromErr (err )
@@ -641,6 +655,7 @@ func resourceDomainsRegistrationDelete(ctx context.Context, d *schema.ResourceDa
641
655
if httperrors .Is404 (err ) {
642
656
continue
643
657
}
658
+
644
659
return diag .FromErr (fmt .Errorf ("failed to get domain details for %s: %w" , domainName , err ))
645
660
}
646
661
0 commit comments