Skip to content

Commit 97c7559

Browse files
committed
fix lint
fix error fix doc fix tf lint fix lint fix lint fix lint fix lint fix lint cleanup: remove commented helpers
1 parent 3e6601a commit 97c7559

6 files changed

+1841
-796
lines changed

docs/resources/domain_domains_registration.md

+2
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ The following arguments are supported:
107107

108108
## Attributes Reference
109109

110+
In addition to all arguments above, the following attributes are exported:
111+
110112
- `id`: The ID of the domain registration.
111113
- `updated_at`: Timestamp of the last update.
112114
- `expired_at`: Expiration date/time of the domain registration.

internal/services/domain/domains_registration.go

+23-8
Original file line numberDiff line numberDiff line change
@@ -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

internal/services/domain/domains_registration_test.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package domain_test
22

33
import (
4+
"context"
45
"fmt"
56
"testing"
67

@@ -16,7 +17,7 @@ func TestAccDomainRegistration_SingleDomainWithUpdate(t *testing.T) {
1617
tt := acctest.NewTestTools(t)
1718
defer tt.Cleanup()
1819

19-
singleDomain := "test-single-updates34" + ".com" // à adapter
20+
singleDomain := "test-single-updates35" + ".com"
2021

2122
resource.ParallelTest(t, resource.TestCase{
2223
PreCheck: func() { acctest.PreCheck(t) },
@@ -168,7 +169,8 @@ func testAccCheckDomainStatus(tt *acctest.TestTools, expectedAutoRenew, expected
168169
}
169170

170171
registrarAPI := domain.NewRegistrarDomainAPI(tt.Meta)
171-
domainNames, err := domain.ExtractDomainsFromTaskID(nil, rs.Primary.ID, registrarAPI)
172+
173+
domainNames, err := domain.ExtractDomainsFromTaskID(context.TODO(), rs.Primary.ID, registrarAPI)
172174
if err != nil {
173175
return fmt.Errorf("error extracting domains: %w", err)
174176
}
@@ -177,18 +179,21 @@ func testAccCheckDomainStatus(tt *acctest.TestTools, expectedAutoRenew, expected
177179
domainResp, getErr := registrarAPI.GetDomain(&domainSDK.RegistrarAPIGetDomainRequest{
178180
Domain: domainName,
179181
})
182+
180183
if getErr != nil {
181184
return fmt.Errorf("failed to get details for domain %s: %w", domainName, getErr)
182185
}
183186

184187
if domainResp.AutoRenewStatus.String() != expectedAutoRenew {
185188
return fmt.Errorf("domain %s has auto_renew status %s, expected %s", domainName, domainResp.AutoRenewStatus, expectedAutoRenew)
186189
}
190+
187191
if domainResp.Dnssec.Status.String() != expectedDNSSEC {
188192
return fmt.Errorf("domain %s has dnssec status %s, expected %s", domainName, domainResp.Dnssec.Status.String(), expectedDNSSEC)
189193
}
190194
}
191195
}
196+
192197
return nil
193198
}
194199
}
@@ -202,9 +207,9 @@ func testAccCheckDomainDestroy(tt *acctest.TestTools) resource.TestCheckFunc {
202207

203208
registrarAPI := domain.NewRegistrarDomainAPI(tt.Meta)
204209

205-
domainNames, err := domain.ExtractDomainsFromTaskID(nil, rs.Primary.ID, registrarAPI)
210+
domainNames, err := domain.ExtractDomainsFromTaskID(context.TODO(), rs.Primary.ID, registrarAPI)
206211
if err != nil {
207-
return nil
212+
return err
208213
}
209214

210215
for _, domainName := range domainNames {
@@ -215,6 +220,7 @@ func testAccCheckDomainDestroy(tt *acctest.TestTools) resource.TestCheckFunc {
215220
if httperrors.Is404(getErr) {
216221
continue
217222
}
223+
218224
return fmt.Errorf("failed to get domain details for %s: %w", domainName, getErr)
219225
}
220226

@@ -227,6 +233,7 @@ func testAccCheckDomainDestroy(tt *acctest.TestTools) resource.TestCheckFunc {
227233
}
228234
}
229235
}
236+
230237
return nil
231238
}
232239
}

0 commit comments

Comments
 (0)