Skip to content

Commit c74497f

Browse files
authored
feat(lb): enhance IP validation in static_config (#2164)
* feat(lb): enhance IP validation in static_config * fix test name
1 parent 6bd7d5d commit c74497f

File tree

6 files changed

+1407
-1
lines changed

6 files changed

+1407
-1
lines changed

scaleway/resource_lb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func resourceScalewayLb() *schema.Resource {
112112
Optional: true,
113113
Elem: &schema.Schema{
114114
Type: schema.TypeString,
115-
ValidateFunc: validation.IsIPAddress,
115+
ValidateFunc: validateStandaloneIPorCIDR(),
116116
},
117117
MaxItems: 1,
118118
},

scaleway/resource_lb_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,74 @@ func TestAccScalewayLbLb_WithIP(t *testing.T) {
483483
})
484484
}
485485

486+
func TestAccScalewayLbLb_WithStaticIPCIDR(t *testing.T) {
487+
tt := NewTestTools(t)
488+
defer tt.Cleanup()
489+
resource.ParallelTest(t, resource.TestCase{
490+
PreCheck: func() { testAccPreCheck(t) },
491+
ProviderFactories: tt.ProviderFactories,
492+
CheckDestroy: testAccCheckScalewayLbDestroy(tt),
493+
Steps: []resource.TestStep{
494+
{
495+
Config: `
496+
resource "scaleway_lb_ip" "ip01" {}
497+
498+
resource "scaleway_vpc_private_network" "pn" {
499+
name = "pn-with-lb-static"
500+
}
501+
502+
resource "scaleway_lb" "lb01" {
503+
ip_id = scaleway_lb_ip.ip01.id
504+
name = "test-lb-with-pn-static-cidr"
505+
type = "LB-S"
506+
private_network {
507+
private_network_id = scaleway_vpc_private_network.pn.id
508+
static_config = ["192.168.1.1/25"]
509+
}
510+
}
511+
`,
512+
Check: resource.ComposeTestCheckFunc(
513+
testAccCheckScalewayLbExists(tt, "scaleway_lb.lb01"),
514+
testAccCheckScalewayLbIPExists(tt, "scaleway_lb_ip.ip01"),
515+
resource.TestCheckResourceAttr("scaleway_lb.lb01",
516+
"private_network.0.static_config.0", "192.168.1.1/25"),
517+
),
518+
},
519+
},
520+
})
521+
}
522+
523+
func TestAccScalewayLbLb_InvalidStaticConfig(t *testing.T) {
524+
tt := NewTestTools(t)
525+
defer tt.Cleanup()
526+
resource.ParallelTest(t, resource.TestCase{
527+
PreCheck: func() { testAccPreCheck(t) },
528+
ProviderFactories: tt.ProviderFactories,
529+
CheckDestroy: testAccCheckScalewayLbDestroy(tt),
530+
Steps: []resource.TestStep{
531+
{
532+
Config: `
533+
resource "scaleway_lb_ip" "ip01" {}
534+
535+
resource "scaleway_vpc_private_network" "pn" {
536+
name = "pn-with-lb-to-static"
537+
}
538+
539+
resource "scaleway_lb" "lb01" {
540+
ip_id = scaleway_lb_ip.ip01.id
541+
name = "test-lb-with-invalid_ip"
542+
type = "LB-S"
543+
private_network {
544+
private_network_id = scaleway_vpc_private_network.pn.id
545+
static_config = ["472.16.0.100/24"]
546+
}
547+
}`,
548+
ExpectError: regexp.MustCompile("\".+\" is not a valid IP address or CIDR notation: .+"),
549+
},
550+
},
551+
})
552+
}
553+
486554
func TestAccScalewayLbLb_WithPrivateNetworksOnDHCPConfig(t *testing.T) {
487555
tt := NewTestTools(t)
488556
defer tt.Cleanup()
Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
---
2+
version: 1
3+
interactions:
4+
- request:
5+
body: '{"project_id":"564aa517-68b0-4fd7-8c8c-d21c4bcdcbd5","reverse":null}'
6+
form: {}
7+
headers:
8+
Content-Type:
9+
- application/json
10+
User-Agent:
11+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.0; darwin; amd64) terraform-provider/develop
12+
terraform/terraform-tests
13+
url: https://api.scaleway.com/lb/v1/zones/fr-par-1/ips
14+
method: POST
15+
response:
16+
body: '{"id":"52ec682b-e8d9-4483-b356-ad8ef40fc63e","ip_address":"51.158.57.58","lb_id":null,"organization_id":"564aa517-68b0-4fd7-8c8c-d21c4bcdcbd5","project_id":"564aa517-68b0-4fd7-8c8c-d21c4bcdcbd5","region":"fr-par","reverse":"51-158-57-58.lb.fr-par.scw.cloud","zone":"fr-par-1"}'
17+
headers:
18+
Content-Length:
19+
- "276"
20+
Content-Security-Policy:
21+
- default-src 'none'; frame-ancestors 'none'
22+
Content-Type:
23+
- application/json
24+
Date:
25+
- Fri, 13 Oct 2023 16:17:50 GMT
26+
Server:
27+
- Scaleway API-Gateway
28+
Strict-Transport-Security:
29+
- max-age=63072000
30+
X-Content-Type-Options:
31+
- nosniff
32+
X-Frame-Options:
33+
- DENY
34+
X-Request-Id:
35+
- 22d47571-c817-4de7-81c1-9085f7b76c85
36+
status: 200 OK
37+
code: 200
38+
duration: ""
39+
- request:
40+
body: ""
41+
form: {}
42+
headers:
43+
User-Agent:
44+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.0; darwin; amd64) terraform-provider/develop
45+
terraform/terraform-tests
46+
url: https://api.scaleway.com/lb/v1/zones/fr-par-1/ips/52ec682b-e8d9-4483-b356-ad8ef40fc63e
47+
method: GET
48+
response:
49+
body: '{"id":"52ec682b-e8d9-4483-b356-ad8ef40fc63e","ip_address":"51.158.57.58","lb_id":null,"organization_id":"564aa517-68b0-4fd7-8c8c-d21c4bcdcbd5","project_id":"564aa517-68b0-4fd7-8c8c-d21c4bcdcbd5","region":"fr-par","reverse":"51-158-57-58.lb.fr-par.scw.cloud","zone":"fr-par-1"}'
50+
headers:
51+
Content-Length:
52+
- "276"
53+
Content-Security-Policy:
54+
- default-src 'none'; frame-ancestors 'none'
55+
Content-Type:
56+
- application/json
57+
Date:
58+
- Fri, 13 Oct 2023 16:17:50 GMT
59+
Server:
60+
- Scaleway API-Gateway
61+
Strict-Transport-Security:
62+
- max-age=63072000
63+
X-Content-Type-Options:
64+
- nosniff
65+
X-Frame-Options:
66+
- DENY
67+
X-Request-Id:
68+
- e7774fae-0d15-4436-bd9e-751af2d3aa7d
69+
status: 200 OK
70+
code: 200
71+
duration: ""
72+
- request:
73+
body: '{"name":"pn-with-lb-to-static","project_id":"564aa517-68b0-4fd7-8c8c-d21c4bcdcbd5","tags":null,"subnets":null,"vpc_id":null}'
74+
form: {}
75+
headers:
76+
Content-Type:
77+
- application/json
78+
User-Agent:
79+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.0; darwin; amd64) terraform-provider/develop
80+
terraform/terraform-tests
81+
url: https://api.scaleway.com/vpc/v2/regions/fr-par/private-networks
82+
method: POST
83+
response:
84+
body: '{"created_at":"2023-10-13T16:17:50.861367Z","dhcp_enabled":true,"id":"63450d99-30e3-4fa6-aea7-63fc60d8d22f","name":"pn-with-lb-to-static","organization_id":"564aa517-68b0-4fd7-8c8c-d21c4bcdcbd5","project_id":"564aa517-68b0-4fd7-8c8c-d21c4bcdcbd5","region":"fr-par","subnets":[{"created_at":"2023-10-13T16:17:50.861367Z","id":"48480cce-fcf9-4e98-92a6-e1707dbf99c2","subnet":"172.16.52.0/22","updated_at":"2023-10-13T16:17:50.861367Z"},{"created_at":"2023-10-13T16:17:50.861367Z","id":"dbaa7ad5-358a-4820-9b2c-b4985663b3c7","subnet":"fd46:78ab:30b8:9f3::/64","updated_at":"2023-10-13T16:17:50.861367Z"}],"tags":[],"updated_at":"2023-10-13T16:17:50.861367Z","vpc_id":"086a5171-f7ab-4667-a231-840a81203f19"}'
85+
headers:
86+
Content-Length:
87+
- "703"
88+
Content-Security-Policy:
89+
- default-src 'none'; frame-ancestors 'none'
90+
Content-Type:
91+
- application/json
92+
Date:
93+
- Fri, 13 Oct 2023 16:17:51 GMT
94+
Server:
95+
- Scaleway API-Gateway
96+
Strict-Transport-Security:
97+
- max-age=63072000
98+
X-Content-Type-Options:
99+
- nosniff
100+
X-Frame-Options:
101+
- DENY
102+
X-Request-Id:
103+
- ac42daaf-f206-4e82-9e44-b76dc2a9e722
104+
status: 200 OK
105+
code: 200
106+
duration: ""
107+
- request:
108+
body: ""
109+
form: {}
110+
headers:
111+
User-Agent:
112+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.0; darwin; amd64) terraform-provider/develop
113+
terraform/terraform-tests
114+
url: https://api.scaleway.com/vpc/v2/regions/fr-par/private-networks/63450d99-30e3-4fa6-aea7-63fc60d8d22f
115+
method: GET
116+
response:
117+
body: '{"created_at":"2023-10-13T16:17:50.861367Z","dhcp_enabled":true,"id":"63450d99-30e3-4fa6-aea7-63fc60d8d22f","name":"pn-with-lb-to-static","organization_id":"564aa517-68b0-4fd7-8c8c-d21c4bcdcbd5","project_id":"564aa517-68b0-4fd7-8c8c-d21c4bcdcbd5","region":"fr-par","subnets":[{"created_at":"2023-10-13T16:17:50.861367Z","id":"48480cce-fcf9-4e98-92a6-e1707dbf99c2","subnet":"172.16.52.0/22","updated_at":"2023-10-13T16:17:50.861367Z"},{"created_at":"2023-10-13T16:17:50.861367Z","id":"dbaa7ad5-358a-4820-9b2c-b4985663b3c7","subnet":"fd46:78ab:30b8:9f3::/64","updated_at":"2023-10-13T16:17:50.861367Z"}],"tags":[],"updated_at":"2023-10-13T16:17:50.861367Z","vpc_id":"086a5171-f7ab-4667-a231-840a81203f19"}'
118+
headers:
119+
Content-Length:
120+
- "703"
121+
Content-Security-Policy:
122+
- default-src 'none'; frame-ancestors 'none'
123+
Content-Type:
124+
- application/json
125+
Date:
126+
- Fri, 13 Oct 2023 16:17:51 GMT
127+
Server:
128+
- Scaleway API-Gateway
129+
Strict-Transport-Security:
130+
- max-age=63072000
131+
X-Content-Type-Options:
132+
- nosniff
133+
X-Frame-Options:
134+
- DENY
135+
X-Request-Id:
136+
- 316d370e-efc8-47fa-9079-9a45f7b495a3
137+
status: 200 OK
138+
code: 200
139+
duration: ""
140+
- request:
141+
body: ""
142+
form: {}
143+
headers:
144+
User-Agent:
145+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.0; darwin; amd64) terraform-provider/develop
146+
terraform/terraform-tests
147+
url: https://api.scaleway.com/lb/v1/zones/fr-par-1/ips/52ec682b-e8d9-4483-b356-ad8ef40fc63e
148+
method: GET
149+
response:
150+
body: '{"id":"52ec682b-e8d9-4483-b356-ad8ef40fc63e","ip_address":"51.158.57.58","lb_id":null,"organization_id":"564aa517-68b0-4fd7-8c8c-d21c4bcdcbd5","project_id":"564aa517-68b0-4fd7-8c8c-d21c4bcdcbd5","region":"fr-par","reverse":"51-158-57-58.lb.fr-par.scw.cloud","zone":"fr-par-1"}'
151+
headers:
152+
Content-Length:
153+
- "276"
154+
Content-Security-Policy:
155+
- default-src 'none'; frame-ancestors 'none'
156+
Content-Type:
157+
- application/json
158+
Date:
159+
- Fri, 13 Oct 2023 16:17:51 GMT
160+
Server:
161+
- Scaleway API-Gateway
162+
Strict-Transport-Security:
163+
- max-age=63072000
164+
X-Content-Type-Options:
165+
- nosniff
166+
X-Frame-Options:
167+
- DENY
168+
X-Request-Id:
169+
- 61e6a29c-0bf0-476f-9c9f-87440fb57617
170+
status: 200 OK
171+
code: 200
172+
duration: ""
173+
- request:
174+
body: ""
175+
form: {}
176+
headers:
177+
User-Agent:
178+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.0; darwin; amd64) terraform-provider/develop
179+
terraform/terraform-tests
180+
url: https://api.scaleway.com/lb/v1/zones/fr-par-1/ips/52ec682b-e8d9-4483-b356-ad8ef40fc63e
181+
method: DELETE
182+
response:
183+
body: ""
184+
headers:
185+
Content-Security-Policy:
186+
- default-src 'none'; frame-ancestors 'none'
187+
Content-Type:
188+
- application/json
189+
Date:
190+
- Fri, 13 Oct 2023 16:17:52 GMT
191+
Server:
192+
- Scaleway API-Gateway
193+
Strict-Transport-Security:
194+
- max-age=63072000
195+
X-Content-Type-Options:
196+
- nosniff
197+
X-Frame-Options:
198+
- DENY
199+
X-Request-Id:
200+
- 6f597c77-dce9-4c12-8483-ecad600475a8
201+
status: 204 No Content
202+
code: 204
203+
duration: ""
204+
- request:
205+
body: ""
206+
form: {}
207+
headers:
208+
User-Agent:
209+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.0; darwin; amd64) terraform-provider/develop
210+
terraform/terraform-tests
211+
url: https://api.scaleway.com/vpc/v2/regions/fr-par/private-networks/63450d99-30e3-4fa6-aea7-63fc60d8d22f
212+
method: DELETE
213+
response:
214+
body: ""
215+
headers:
216+
Content-Security-Policy:
217+
- default-src 'none'; frame-ancestors 'none'
218+
Content-Type:
219+
- application/json
220+
Date:
221+
- Fri, 13 Oct 2023 16:17:52 GMT
222+
Server:
223+
- Scaleway API-Gateway
224+
Strict-Transport-Security:
225+
- max-age=63072000
226+
X-Content-Type-Options:
227+
- nosniff
228+
X-Frame-Options:
229+
- DENY
230+
X-Request-Id:
231+
- b288760c-2a68-474a-b467-23fbba680561
232+
status: 204 No Content
233+
code: 204
234+
duration: ""

0 commit comments

Comments
 (0)