Skip to content

Commit 2dbf3b7

Browse files
author
protobuf-ci-cd
committed
fix(domain): handle root zone ID without leading dot
fix test fix lint
1 parent 38d87a6 commit 2dbf3b7

File tree

5 files changed

+395
-7
lines changed

5 files changed

+395
-7
lines changed

internal/services/domain/helpers.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,3 +623,11 @@ func FlattenDSRecord(dsRecords []*domain.DSRecord) []any {
623623

624624
return results
625625
}
626+
627+
func BuildZoneName(subdomain, domain string) string {
628+
if subdomain == "" {
629+
return domain
630+
}
631+
632+
return fmt.Sprintf("%s.%s", subdomain, domain)
633+
}
Lines changed: 346 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,346 @@
1+
---
2+
version: 2
3+
interactions:
4+
- id: 0
5+
request:
6+
proto: HTTP/1.1
7+
proto_major: 1
8+
proto_minor: 1
9+
content_length: 0
10+
transfer_encoding: []
11+
trailer: {}
12+
host: api.scaleway.com
13+
remote_addr: ""
14+
request_uri: ""
15+
body: ""
16+
form: {}
17+
headers:
18+
User-Agent:
19+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests
20+
url: https://api.scaleway.com/domain/v2beta1/dns-zones?dns_zones=scaleway-terraform.com&domain=&order_by=domain_asc
21+
method: GET
22+
response:
23+
proto: HTTP/2.0
24+
proto_major: 2
25+
proto_minor: 0
26+
transfer_encoding: []
27+
trailer: {}
28+
content_length: 353
29+
uncompressed: false
30+
body: '{"dns_zones":[{"domain":"scaleway-terraform.com","linked_products":[],"message":null,"ns":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_default":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_master":[],"project_id":"105bdce1-64c0-48ab-899d-868455867ecf","status":"active","subdomain":"","updated_at":"2025-07-10T01:32:17Z"}],"total_count":1}'
31+
headers:
32+
Content-Length:
33+
- "353"
34+
Content-Security-Policy:
35+
- default-src 'none'; frame-ancestors 'none'
36+
Content-Type:
37+
- application/json
38+
Date:
39+
- Thu, 10 Jul 2025 12:28:13 GMT
40+
Server:
41+
- Scaleway API Gateway (fr-par-3;edge02)
42+
Strict-Transport-Security:
43+
- max-age=63072000
44+
X-Content-Type-Options:
45+
- nosniff
46+
X-Frame-Options:
47+
- DENY
48+
X-Request-Id:
49+
- 9795d279-d40b-4308-829a-7c05455e20fc
50+
status: 200 OK
51+
code: 200
52+
duration: 580.768208ms
53+
- id: 1
54+
request:
55+
proto: HTTP/1.1
56+
proto_major: 1
57+
proto_minor: 1
58+
content_length: 0
59+
transfer_encoding: []
60+
trailer: {}
61+
host: api.scaleway.com
62+
remote_addr: ""
63+
request_uri: ""
64+
body: ""
65+
form: {}
66+
headers:
67+
User-Agent:
68+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests
69+
url: https://api.scaleway.com/domain/v2beta1/dns-zones?dns_zones=scaleway-terraform.com&domain=&order_by=domain_asc
70+
method: GET
71+
response:
72+
proto: HTTP/2.0
73+
proto_major: 2
74+
proto_minor: 0
75+
transfer_encoding: []
76+
trailer: {}
77+
content_length: 353
78+
uncompressed: false
79+
body: '{"dns_zones":[{"domain":"scaleway-terraform.com","linked_products":[],"message":null,"ns":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_default":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_master":[],"project_id":"105bdce1-64c0-48ab-899d-868455867ecf","status":"active","subdomain":"","updated_at":"2025-07-10T01:32:17Z"}],"total_count":1}'
80+
headers:
81+
Content-Length:
82+
- "353"
83+
Content-Security-Policy:
84+
- default-src 'none'; frame-ancestors 'none'
85+
Content-Type:
86+
- application/json
87+
Date:
88+
- Thu, 10 Jul 2025 12:28:13 GMT
89+
Server:
90+
- Scaleway API Gateway (fr-par-3;edge02)
91+
Strict-Transport-Security:
92+
- max-age=63072000
93+
X-Content-Type-Options:
94+
- nosniff
95+
X-Frame-Options:
96+
- DENY
97+
X-Request-Id:
98+
- d9179ec6-2a4a-4ce8-bb71-a9f221ea9a45
99+
status: 200 OK
100+
code: 200
101+
duration: 124.617584ms
102+
- id: 2
103+
request:
104+
proto: HTTP/1.1
105+
proto_major: 1
106+
proto_minor: 1
107+
content_length: 0
108+
transfer_encoding: []
109+
trailer: {}
110+
host: api.scaleway.com
111+
remote_addr: ""
112+
request_uri: ""
113+
body: ""
114+
form: {}
115+
headers:
116+
User-Agent:
117+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests
118+
url: https://api.scaleway.com/domain/v2beta1/dns-zones?dns_zones=scaleway-terraform.com&domain=&order_by=domain_asc
119+
method: GET
120+
response:
121+
proto: HTTP/2.0
122+
proto_major: 2
123+
proto_minor: 0
124+
transfer_encoding: []
125+
trailer: {}
126+
content_length: 353
127+
uncompressed: false
128+
body: '{"dns_zones":[{"domain":"scaleway-terraform.com","linked_products":[],"message":null,"ns":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_default":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_master":[],"project_id":"105bdce1-64c0-48ab-899d-868455867ecf","status":"active","subdomain":"","updated_at":"2025-07-10T01:32:17Z"}],"total_count":1}'
129+
headers:
130+
Content-Length:
131+
- "353"
132+
Content-Security-Policy:
133+
- default-src 'none'; frame-ancestors 'none'
134+
Content-Type:
135+
- application/json
136+
Date:
137+
- Thu, 10 Jul 2025 12:28:13 GMT
138+
Server:
139+
- Scaleway API Gateway (fr-par-3;edge02)
140+
Strict-Transport-Security:
141+
- max-age=63072000
142+
X-Content-Type-Options:
143+
- nosniff
144+
X-Frame-Options:
145+
- DENY
146+
X-Request-Id:
147+
- e9c2c2e2-552c-44ad-a258-540c78454539
148+
status: 200 OK
149+
code: 200
150+
duration: 165.313583ms
151+
- id: 3
152+
request:
153+
proto: HTTP/1.1
154+
proto_major: 1
155+
proto_minor: 1
156+
content_length: 0
157+
transfer_encoding: []
158+
trailer: {}
159+
host: api.scaleway.com
160+
remote_addr: ""
161+
request_uri: ""
162+
body: ""
163+
form: {}
164+
headers:
165+
User-Agent:
166+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests
167+
url: https://api.scaleway.com/domain/v2beta1/dns-zones?dns_zones=scaleway-terraform.com&domain=&order_by=domain_asc&project_id=105bdce1-64c0-48ab-899d-868455867ecf
168+
method: GET
169+
response:
170+
proto: HTTP/2.0
171+
proto_major: 2
172+
proto_minor: 0
173+
transfer_encoding: []
174+
trailer: {}
175+
content_length: 353
176+
uncompressed: false
177+
body: '{"dns_zones":[{"domain":"scaleway-terraform.com","linked_products":[],"message":null,"ns":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_default":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_master":[],"project_id":"105bdce1-64c0-48ab-899d-868455867ecf","status":"active","subdomain":"","updated_at":"2025-07-10T01:32:17Z"}],"total_count":1}'
178+
headers:
179+
Content-Length:
180+
- "353"
181+
Content-Security-Policy:
182+
- default-src 'none'; frame-ancestors 'none'
183+
Content-Type:
184+
- application/json
185+
Date:
186+
- Thu, 10 Jul 2025 12:28:14 GMT
187+
Server:
188+
- Scaleway API Gateway (fr-par-3;edge02)
189+
Strict-Transport-Security:
190+
- max-age=63072000
191+
X-Content-Type-Options:
192+
- nosniff
193+
X-Frame-Options:
194+
- DENY
195+
X-Request-Id:
196+
- e79b782a-af86-4049-8e88-4a9977d76b38
197+
status: 200 OK
198+
code: 200
199+
duration: 342.27975ms
200+
- id: 4
201+
request:
202+
proto: HTTP/1.1
203+
proto_major: 1
204+
proto_minor: 1
205+
content_length: 0
206+
transfer_encoding: []
207+
trailer: {}
208+
host: api.scaleway.com
209+
remote_addr: ""
210+
request_uri: ""
211+
body: ""
212+
form: {}
213+
headers:
214+
User-Agent:
215+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests
216+
url: https://api.scaleway.com/domain/v2beta1/dns-zones?dns_zone=scaleway-terraform.com&domain=&order_by=domain_asc
217+
method: GET
218+
response:
219+
proto: HTTP/2.0
220+
proto_major: 2
221+
proto_minor: 0
222+
transfer_encoding: []
223+
trailer: {}
224+
content_length: 353
225+
uncompressed: false
226+
body: '{"dns_zones":[{"domain":"scaleway-terraform.com","linked_products":[],"message":null,"ns":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_default":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_master":[],"project_id":"105bdce1-64c0-48ab-899d-868455867ecf","status":"active","subdomain":"","updated_at":"2025-07-10T01:32:17Z"}],"total_count":1}'
227+
headers:
228+
Content-Length:
229+
- "353"
230+
Content-Security-Policy:
231+
- default-src 'none'; frame-ancestors 'none'
232+
Content-Type:
233+
- application/json
234+
Date:
235+
- Thu, 10 Jul 2025 12:28:15 GMT
236+
Server:
237+
- Scaleway API Gateway (fr-par-3;edge02)
238+
Strict-Transport-Security:
239+
- max-age=63072000
240+
X-Content-Type-Options:
241+
- nosniff
242+
X-Frame-Options:
243+
- DENY
244+
X-Request-Id:
245+
- 25a108ab-06fe-4b02-a6a0-d72bddf2fd66
246+
status: 200 OK
247+
code: 200
248+
duration: 130.822292ms
249+
- id: 5
250+
request:
251+
proto: HTTP/1.1
252+
proto_major: 1
253+
proto_minor: 1
254+
content_length: 0
255+
transfer_encoding: []
256+
trailer: {}
257+
host: api.scaleway.com
258+
remote_addr: ""
259+
request_uri: ""
260+
body: ""
261+
form: {}
262+
headers:
263+
User-Agent:
264+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests
265+
url: https://api.scaleway.com/domain/v2beta1/dns-zones/scaleway-terraform.com?project_id=105bdce1-64c0-48ab-899d-868455867ecf
266+
method: DELETE
267+
response:
268+
proto: HTTP/2.0
269+
proto_major: 2
270+
proto_minor: 0
271+
transfer_encoding: []
272+
trailer: {}
273+
content_length: 40
274+
uncompressed: false
275+
body: '{"message":"root zone can''t be deleted"}'
276+
headers:
277+
Content-Length:
278+
- "40"
279+
Content-Security-Policy:
280+
- default-src 'none'; frame-ancestors 'none'
281+
Content-Type:
282+
- application/json
283+
Date:
284+
- Thu, 10 Jul 2025 12:28:15 GMT
285+
Server:
286+
- Scaleway API Gateway (fr-par-3;edge02)
287+
Strict-Transport-Security:
288+
- max-age=63072000
289+
X-Content-Type-Options:
290+
- nosniff
291+
X-Frame-Options:
292+
- DENY
293+
X-Request-Id:
294+
- 4e28cbd4-9e4e-4f58-8c5b-f7b8f33613d9
295+
status: 403 Forbidden
296+
code: 403
297+
duration: 73.538916ms
298+
- id: 6
299+
request:
300+
proto: HTTP/1.1
301+
proto_major: 1
302+
proto_minor: 1
303+
content_length: 0
304+
transfer_encoding: []
305+
trailer: {}
306+
host: api.scaleway.com
307+
remote_addr: ""
308+
request_uri: ""
309+
body: ""
310+
form: {}
311+
headers:
312+
User-Agent:
313+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.0; darwin; arm64) terraform-provider/develop terraform/terraform-tests
314+
url: https://api.scaleway.com/domain/v2beta1/dns-zones?dns_zones=scaleway-terraform.com&domain=&order_by=domain_asc
315+
method: GET
316+
response:
317+
proto: HTTP/2.0
318+
proto_major: 2
319+
proto_minor: 0
320+
transfer_encoding: []
321+
trailer: {}
322+
content_length: 353
323+
uncompressed: false
324+
body: '{"dns_zones":[{"domain":"scaleway-terraform.com","linked_products":[],"message":null,"ns":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_default":["ns0.dom.scw.cloud","ns1.dom.scw.cloud"],"ns_master":[],"project_id":"105bdce1-64c0-48ab-899d-868455867ecf","status":"active","subdomain":"","updated_at":"2025-07-10T01:32:17Z"}],"total_count":1}'
325+
headers:
326+
Content-Length:
327+
- "353"
328+
Content-Security-Policy:
329+
- default-src 'none'; frame-ancestors 'none'
330+
Content-Type:
331+
- application/json
332+
Date:
333+
- Thu, 10 Jul 2025 12:28:15 GMT
334+
Server:
335+
- Scaleway API Gateway (fr-par-3;edge02)
336+
Strict-Transport-Security:
337+
- max-age=63072000
338+
X-Content-Type-Options:
339+
- nosniff
340+
X-Frame-Options:
341+
- DENY
342+
X-Request-Id:
343+
- 3b2e5b39-7a1a-4ec1-9e8d-428f51ade5a1
344+
status: 200 OK
345+
code: 200
346+
duration: 123.945083ms

internal/services/domain/zone.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func resourceDomainZoneCreate(ctx context.Context, d *schema.ResourceData, m any
8888

8989
domainName := strings.ToLower(d.Get("domain").(string))
9090
subdomainName := strings.ToLower(d.Get("subdomain").(string))
91-
zoneName := fmt.Sprintf("%s.%s", subdomainName, domainName)
91+
zoneName := BuildZoneName(subdomainName, domainName)
9292

9393
zones, err := domainAPI.ListDNSZones(&domain.ListDNSZonesRequest{
9494
ProjectID: types.ExpandStringPtr(d.Get("project_id")),
@@ -100,7 +100,7 @@ func resourceDomainZoneCreate(ctx context.Context, d *schema.ResourceData, m any
100100

101101
for i := range zones.DNSZones {
102102
if zones.DNSZones[i].Domain == domainName && zones.DNSZones[i].Subdomain == subdomainName {
103-
d.SetId(fmt.Sprintf("%s.%s", subdomainName, domainName))
103+
d.SetId(BuildZoneName(subdomainName, domainName))
104104

105105
return resourceDomainZoneRead(ctx, d, m)
106106
}
@@ -121,7 +121,7 @@ func resourceDomainZoneCreate(ctx context.Context, d *schema.ResourceData, m any
121121
return diag.FromErr(err)
122122
}
123123

124-
d.SetId(fmt.Sprintf("%s.%s", dnsZone.Subdomain, dnsZone.Domain))
124+
d.SetId(BuildZoneName(dnsZone.Subdomain, dnsZone.Domain))
125125

126126
return resourceDomainZoneRead(ctx, d, m)
127127
}

0 commit comments

Comments
 (0)