@@ -417,10 +417,12 @@ func resourceDomainsRegistrationCreate(ctx context.Context, d *schema.ResourceDa
417417 registrarAPI := NewRegistrarDomainAPI (m )
418418
419419 projectID := d .Get ("project_id" ).(string )
420+
420421 domainNames := make ([]string , 0 )
421422 for _ , v := range d .Get ("domain_names" ).([]interface {}) {
422423 domainNames = append (domainNames , v .(string ))
423424 }
425+
424426 durationInYears := uint32 (d .Get ("duration_in_years" ).(int ))
425427
426428 buyDomainsRequest := & domain.RegistrarAPIBuyDomainsRequest {
@@ -430,6 +432,7 @@ func resourceDomainsRegistrationCreate(ctx context.Context, d *schema.ResourceDa
430432 }
431433
432434 ownerContactID := d .Get ("owner_contact_id" ).(string )
435+
433436 if ownerContactID != "" {
434437 buyDomainsRequest .OwnerContactID = & ownerContactID
435438 } else if ownerContacts , ok := d .GetOk ("owner_contact" ); ok {
@@ -469,20 +472,25 @@ func resourceDomainsRegistrationsRead(ctx context.Context, d *schema.ResourceDat
469472 if err != nil {
470473 return diag .FromErr (err )
471474 }
475+
472476 if len (domainNames ) == 0 {
473477 d .SetId ("" )
478+
474479 return nil
475480 }
476481
477482 firstDomain := domainNames [0 ]
483+
478484 firstResp , err := registrarAPI .GetDomain (& domain.RegistrarAPIGetDomainRequest {
479485 Domain : firstDomain ,
480486 }, scw .WithContext (ctx ))
481487 if err != nil {
482488 if httperrors .Is404 (err ) {
483489 d .SetId ("" )
490+
484491 return nil
485492 }
493+
486494 return diag .FromErr (err )
487495 }
488496
@@ -501,7 +509,6 @@ func resourceDomainsRegistrationsRead(ctx context.Context, d *schema.ResourceDat
501509 }
502510
503511 computedDnssec := false
504-
505512 if firstResp .Dnssec .Status == domain .DomainFeatureStatusEnabled {
506513 computedDnssec = true
507514 }
@@ -536,17 +543,16 @@ func resourceDomainsRegistrationUpdate(ctx context.Context, d *schema.ResourceDa
536543 if err != nil {
537544 return diag .FromErr (err )
538545 }
546+
539547 if len (domainNames ) == 0 {
540548 d .SetId ("" )
541- return nil
542- }
543549
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
546551 }
547552
548553 if d .HasChange ("auto_renew" ) {
549554 newAutoRenew := d .Get ("auto_renew" ).(bool )
555+
550556 for _ , domainName := range domainNames {
551557 domainResp , err := registrarAPI .GetDomain (& domain.RegistrarAPIGetDomainRequest {
552558 Domain : domainName ,
@@ -556,7 +562,8 @@ func resourceDomainsRegistrationUpdate(ctx context.Context, d *schema.ResourceDa
556562 }
557563
558564 if newAutoRenew {
559- if domainResp .AutoRenewStatus != domain .DomainFeatureStatusEnabled && domainResp .AutoRenewStatus != domain .DomainFeatureStatusEnabling {
565+ if domainResp .AutoRenewStatus != domain .DomainFeatureStatusEnabled &&
566+ domainResp .AutoRenewStatus != domain .DomainFeatureStatusEnabling {
560567 _ , err = registrarAPI .EnableDomainAutoRenew (& domain.RegistrarAPIEnableDomainAutoRenewRequest {
561568 Domain : domainName ,
562569 }, scw .WithContext (ctx ))
@@ -565,7 +572,8 @@ func resourceDomainsRegistrationUpdate(ctx context.Context, d *schema.ResourceDa
565572 }
566573 }
567574 } else {
568- if domainResp .AutoRenewStatus == domain .DomainFeatureStatusEnabled || domainResp .AutoRenewStatus == domain .DomainFeatureStatusEnabling {
575+ if domainResp .AutoRenewStatus == domain .DomainFeatureStatusEnabled ||
576+ domainResp .AutoRenewStatus == domain .DomainFeatureStatusEnabling {
569577 _ , err = registrarAPI .DisableDomainAutoRenew (& domain.RegistrarAPIDisableDomainAutoRenewRequest {
570578 Domain : domainName ,
571579 }, scw .WithContext (ctx ))
@@ -574,6 +582,7 @@ func resourceDomainsRegistrationUpdate(ctx context.Context, d *schema.ResourceDa
574582 }
575583 }
576584 }
585+
577586 _ , err = waitForAutoRenewStatus (ctx , registrarAPI , domainName , d .Timeout (schema .TimeoutUpdate ))
578587 if err != nil {
579588 return diag .FromErr (err )
@@ -583,6 +592,7 @@ func resourceDomainsRegistrationUpdate(ctx context.Context, d *schema.ResourceDa
583592
584593 if d .HasChange ("dnssec" ) {
585594 newDnssec := d .Get ("dnssec" ).(bool )
595+
586596 for _ , domainName := range domainNames {
587597 domainResp , err := registrarAPI .GetDomain (& domain.RegistrarAPIGetDomainRequest {
588598 Domain : domainName ,
@@ -593,27 +603,31 @@ func resourceDomainsRegistrationUpdate(ctx context.Context, d *schema.ResourceDa
593603
594604 if newDnssec {
595605 var dsRecord * domain.DSRecord
606+
596607 if v , ok := d .GetOk ("ds_record" ); ok {
597608 dsRecordList := v .([]interface {})
598609 if len (dsRecordList ) > 0 && dsRecordList [0 ] != nil {
599610 dsRecord = ExpandDSRecord (dsRecordList )
600611 }
601612 }
613+
602614 _ , err = registrarAPI .EnableDomainDNSSEC (& domain.RegistrarAPIEnableDomainDNSSECRequest {
603615 Domain : domainName ,
604616 DsRecord : dsRecord ,
605617 }, scw .WithContext (ctx ))
606618 if err != nil {
607619 return diag .FromErr (fmt .Errorf ("failed to enable dnssec for %s: %w" , domainName , err ))
608620 }
609- } else if domainResp .Dnssec != nil && domainResp .Dnssec .Status == domain .DomainFeatureStatusEnabled {
621+ } else if domainResp .Dnssec != nil &&
622+ domainResp .Dnssec .Status == domain .DomainFeatureStatusEnabled {
610623 _ , err = registrarAPI .DisableDomainDNSSEC (& domain.RegistrarAPIDisableDomainDNSSECRequest {
611624 Domain : domainName ,
612625 }, scw .WithContext (ctx ))
613626 if err != nil {
614627 return diag .FromErr (fmt .Errorf ("failed to disable dnssec for %s: %w" , domainName , err ))
615628 }
616629 }
630+
617631 _ , err = waitForDNSSECStatus (ctx , registrarAPI , domainName , d .Timeout (schema .TimeoutUpdate ))
618632 if err != nil {
619633 return diag .FromErr (err )
@@ -641,6 +655,7 @@ func resourceDomainsRegistrationDelete(ctx context.Context, d *schema.ResourceDa
641655 if httperrors .Is404 (err ) {
642656 continue
643657 }
658+
644659 return diag .FromErr (fmt .Errorf ("failed to get domain details for %s: %w" , domainName , err ))
645660 }
646661
0 commit comments