Skip to content

Commit ccc68e7

Browse files
jerjakoremyleone
authored andcommitted
fix(domain): test create zone (scaleway#1098)
1 parent 3567e92 commit ccc68e7

10 files changed

+850
-760
lines changed

scaleway/data_source_domain_zone_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func TestAccScalewayDataSourceDomainZone_Basic(t *testing.T) {
1111
tt := NewTestTools(t)
1212
defer tt.Cleanup()
1313

14-
testDNSZone := "test-zone"
14+
testDNSZone := "test-zone2"
1515

1616
resource.ParallelTest(t, resource.TestCase{
1717
PreCheck: func() { testAccPreCheck(t) },

scaleway/resource_domain_zone.go

+28-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package scaleway
33
import (
44
"context"
55
"fmt"
6+
"strings"
67

78
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
89
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -82,15 +83,38 @@ func resourceScalewayDomainZone() *schema.Resource {
8283
func resourceScalewayDomainZoneCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
8384
domainAPI := newDomainAPI(meta)
8485

86+
domainName := strings.ToLower(d.Get("domain").(string))
87+
subdomainName := strings.ToLower(d.Get("subdomain").(string))
88+
zoneName := fmt.Sprintf("%s.%s", subdomainName, domainName)
89+
90+
zones, err := domainAPI.ListDNSZones(&domain.ListDNSZonesRequest{
91+
ProjectID: expandStringPtr(d.Get("project_id")),
92+
DNSZone: zoneName,
93+
}, scw.WithContext(ctx))
94+
if err != nil {
95+
return diag.FromErr(err)
96+
}
97+
98+
for i := range zones.DNSZones {
99+
if zones.DNSZones[i].Domain == domainName && zones.DNSZones[i].Subdomain == subdomainName {
100+
d.SetId(fmt.Sprintf("%s.%s", subdomainName, domainName))
101+
102+
return resourceScalewayDomainZoneRead(ctx, d, meta)
103+
}
104+
}
105+
85106
var dnsZone *domain.DNSZone
86107

87-
dnsZone, err := domainAPI.CreateDNSZone(&domain.CreateDNSZoneRequest{
108+
dnsZone, err = domainAPI.CreateDNSZone(&domain.CreateDNSZoneRequest{
88109
ProjectID: d.Get("project_id").(string),
89-
Domain: d.Get("domain").(string),
90-
Subdomain: d.Get("subdomain").(string),
110+
Domain: domainName,
111+
Subdomain: subdomainName,
91112
}, scw.WithContext(ctx))
92113

93114
if err != nil {
115+
if is409Error(err) {
116+
return resourceScalewayDomainZoneRead(ctx, d, meta)
117+
}
94118
return diag.FromErr(err)
95119
}
96120
d.SetId(fmt.Sprintf("%s.%s", dnsZone.Subdomain, dnsZone.Domain))
@@ -160,7 +184,7 @@ func resourceScalewayDomainZoneDelete(ctx context.Context, d *schema.ResourceDat
160184
DNSZone: d.Id(),
161185
}, scw.WithContext(ctx))
162186

163-
if err != nil && !is404Error(err) {
187+
if err != nil && !is404Error(err) && !is403Error(err) {
164188
return diag.FromErr(err)
165189
}
166190

scaleway/testdata/data-source-domain-record-basic.cassette.yaml

+355-355
Large diffs are not rendered by default.

scaleway/testdata/data-source-domain-zone-basic.cassette.yaml

+79-46
Large diffs are not rendered by default.

scaleway/testdata/domain-record-basic.cassette.yaml

+122-122
Large diffs are not rendered by default.

scaleway/testdata/domain-record-geo-ip.cassette.yaml

+54-54
Large diffs are not rendered by default.

scaleway/testdata/domain-record-http-service.cassette.yaml

+54-54
Large diffs are not rendered by default.

scaleway/testdata/domain-record-view.cassette.yaml

+54-54
Large diffs are not rendered by default.

scaleway/testdata/domain-record-weighted.cassette.yaml

+54-54
Large diffs are not rendered by default.

scaleway/testdata/domain-zone-basic.cassette.yaml

+49-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,39 @@
11
---
22
version: 1
33
interactions:
4+
- request:
5+
body: ""
6+
form: {}
7+
headers:
8+
User-Agent:
9+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.17.6; linux; amd64) terraform-provider/develop
10+
terraform/terraform-tests
11+
url: https://api.scaleway.com/domain/v2beta1/dns-zones?dns_zone=test-zone.scaleway-terraform.com&domain=&order_by=domain_asc
12+
method: GET
13+
response:
14+
body: '{"total_count":0,"dns_zones":[]}'
15+
headers:
16+
Content-Length:
17+
- "32"
18+
Content-Security-Policy:
19+
- default-src 'none'; frame-ancestors 'none'
20+
Content-Type:
21+
- application/json
22+
Date:
23+
- Thu, 17 Feb 2022 15:18:20 GMT
24+
Server:
25+
- Scaleway API-Gateway
26+
Strict-Transport-Security:
27+
- max-age=63072000
28+
X-Content-Type-Options:
29+
- nosniff
30+
X-Frame-Options:
31+
- DENY
32+
X-Request-Id:
33+
- da08eeac-24b9-494b-b083-201eef472171
34+
status: 200 OK
35+
code: 200
36+
duration: ""
437
- request:
538
body: '{"domain":"scaleway-terraform.com","subdomain":"test-zone","project_id":"fbda9817-5c05-4e1d-aa8d-a1a8b0b80ddf"}'
639
form: {}
@@ -13,7 +46,7 @@ interactions:
1346
url: https://api.scaleway.com/domain/v2beta1/dns-zones
1447
method: POST
1548
response:
16-
body: '{"domain":"scaleway-terraform.com","subdomain":"test-zone","ns":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_default":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_master":[],"status":"active","message":null,"updated_at":"2022-02-15T15:31:48Z","project_id":"fbda9817-5c05-4e1d-aa8d-a1a8b0b80ddf"}'
49+
body: '{"domain":"scaleway-terraform.com","subdomain":"test-zone","ns":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_default":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_master":[],"status":"active","message":null,"updated_at":"2022-02-17T15:18:20Z","project_id":"fbda9817-5c05-4e1d-aa8d-a1a8b0b80ddf"}'
1750
headers:
1851
Content-Length:
1952
- "297"
@@ -22,7 +55,7 @@ interactions:
2255
Content-Type:
2356
- application/json
2457
Date:
25-
- Tue, 15 Feb 2022 15:31:48 GMT
58+
- Thu, 17 Feb 2022 15:18:20 GMT
2659
Server:
2760
- Scaleway API-Gateway
2861
Strict-Transport-Security:
@@ -32,7 +65,7 @@ interactions:
3265
X-Frame-Options:
3366
- DENY
3467
X-Request-Id:
35-
- dd547233-f211-4365-818a-b53de6e709e5
68+
- 21a6807f-c764-4e0e-b7e9-0c0f6457aff1
3669
status: 200 OK
3770
code: 200
3871
duration: ""
@@ -46,7 +79,7 @@ interactions:
4679
url: https://api.scaleway.com/domain/v2beta1/dns-zones?dns_zone=test-zone.scaleway-terraform.com&domain=&order_by=domain_asc
4780
method: GET
4881
response:
49-
body: '{"total_count":1,"dns_zones":[{"domain":"scaleway-terraform.com","subdomain":"test-zone","ns":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_default":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_master":[],"status":"active","message":null,"updated_at":"2022-02-15T15:31:48Z","project_id":"fbda9817-5c05-4e1d-aa8d-a1a8b0b80ddf"}]}'
82+
body: '{"total_count":1,"dns_zones":[{"domain":"scaleway-terraform.com","subdomain":"test-zone","ns":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_default":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_master":[],"status":"active","message":null,"updated_at":"2022-02-17T15:18:20Z","project_id":"fbda9817-5c05-4e1d-aa8d-a1a8b0b80ddf"}]}'
5083
headers:
5184
Content-Length:
5285
- "329"
@@ -55,7 +88,7 @@ interactions:
5588
Content-Type:
5689
- application/json
5790
Date:
58-
- Tue, 15 Feb 2022 15:31:48 GMT
91+
- Thu, 17 Feb 2022 15:18:20 GMT
5992
Server:
6093
- Scaleway API-Gateway
6194
Strict-Transport-Security:
@@ -65,7 +98,7 @@ interactions:
6598
X-Frame-Options:
6699
- DENY
67100
X-Request-Id:
68-
- f78957dd-6919-42a3-bedb-ab292380cac3
101+
- 99191f29-9516-46df-9130-af5dfbc9d38e
69102
status: 200 OK
70103
code: 200
71104
duration: ""
@@ -79,7 +112,7 @@ interactions:
79112
url: https://api.scaleway.com/domain/v2beta1/dns-zones?dns_zone=test-zone.scaleway-terraform.com&domain=&order_by=domain_asc
80113
method: GET
81114
response:
82-
body: '{"total_count":1,"dns_zones":[{"domain":"scaleway-terraform.com","subdomain":"test-zone","ns":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_default":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_master":[],"status":"active","message":null,"updated_at":"2022-02-15T15:31:48Z","project_id":"fbda9817-5c05-4e1d-aa8d-a1a8b0b80ddf"}]}'
115+
body: '{"total_count":1,"dns_zones":[{"domain":"scaleway-terraform.com","subdomain":"test-zone","ns":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_default":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_master":[],"status":"active","message":null,"updated_at":"2022-02-17T15:18:20Z","project_id":"fbda9817-5c05-4e1d-aa8d-a1a8b0b80ddf"}]}'
83116
headers:
84117
Content-Length:
85118
- "329"
@@ -88,7 +121,7 @@ interactions:
88121
Content-Type:
89122
- application/json
90123
Date:
91-
- Tue, 15 Feb 2022 15:31:49 GMT
124+
- Thu, 17 Feb 2022 15:18:21 GMT
92125
Server:
93126
- Scaleway API-Gateway
94127
Strict-Transport-Security:
@@ -98,7 +131,7 @@ interactions:
98131
X-Frame-Options:
99132
- DENY
100133
X-Request-Id:
101-
- 486cf7a3-68f7-49d3-9de7-fb5f693384e5
134+
- 6478819f-f65b-4e14-971a-852edaf6b5e1
102135
status: 200 OK
103136
code: 200
104137
duration: ""
@@ -112,7 +145,7 @@ interactions:
112145
url: https://api.scaleway.com/domain/v2beta1/dns-zones?dns_zone=test-zone.scaleway-terraform.com&domain=&order_by=domain_asc&project_id=fbda9817-5c05-4e1d-aa8d-a1a8b0b80ddf
113146
method: GET
114147
response:
115-
body: '{"total_count":1,"dns_zones":[{"domain":"scaleway-terraform.com","subdomain":"test-zone","ns":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_default":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_master":[],"status":"active","message":null,"updated_at":"2022-02-15T15:31:48Z","project_id":"fbda9817-5c05-4e1d-aa8d-a1a8b0b80ddf"}]}'
148+
body: '{"total_count":1,"dns_zones":[{"domain":"scaleway-terraform.com","subdomain":"test-zone","ns":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_default":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_master":[],"status":"active","message":null,"updated_at":"2022-02-17T15:18:20Z","project_id":"fbda9817-5c05-4e1d-aa8d-a1a8b0b80ddf"}]}'
116149
headers:
117150
Content-Length:
118151
- "329"
@@ -121,7 +154,7 @@ interactions:
121154
Content-Type:
122155
- application/json
123156
Date:
124-
- Tue, 15 Feb 2022 15:31:49 GMT
157+
- Thu, 17 Feb 2022 15:18:21 GMT
125158
Server:
126159
- Scaleway API-Gateway
127160
Strict-Transport-Security:
@@ -131,7 +164,7 @@ interactions:
131164
X-Frame-Options:
132165
- DENY
133166
X-Request-Id:
134-
- e8ec2e49-b24a-497d-b499-d48e70b90205
167+
- 4562a531-3cdc-4275-9ea8-150b3a0dc1e3
135168
status: 200 OK
136169
code: 200
137170
duration: ""
@@ -154,7 +187,7 @@ interactions:
154187
Content-Type:
155188
- application/json
156189
Date:
157-
- Tue, 15 Feb 2022 15:31:50 GMT
190+
- Thu, 17 Feb 2022 15:18:24 GMT
158191
Server:
159192
- Scaleway API-Gateway
160193
Strict-Transport-Security:
@@ -164,7 +197,7 @@ interactions:
164197
X-Frame-Options:
165198
- DENY
166199
X-Request-Id:
167-
- 32744329-079e-429f-aadb-c60ed80aeaa5
200+
- e6d88c9a-39ae-4979-b68e-ef4497d1ab23
168201
status: 200 OK
169202
code: 200
170203
duration: ""
@@ -187,7 +220,7 @@ interactions:
187220
Content-Type:
188221
- application/json
189222
Date:
190-
- Tue, 15 Feb 2022 15:31:50 GMT
223+
- Thu, 17 Feb 2022 15:18:24 GMT
191224
Server:
192225
- Scaleway API-Gateway
193226
Strict-Transport-Security:
@@ -197,7 +230,7 @@ interactions:
197230
X-Frame-Options:
198231
- DENY
199232
X-Request-Id:
200-
- a1aa9ecc-6b87-4877-996d-a6bc230a47c9
233+
- 5c3514ce-33fd-4c6f-ba5a-178be54f4382
201234
status: 200 OK
202235
code: 200
203236
duration: ""

0 commit comments

Comments
 (0)