Skip to content

Commit 8afb07b

Browse files
authored
Fix(lb): fix test case with multiple private networks (#1281)
1 parent 674adda commit 8afb07b

7 files changed

+7148
-1414
lines changed

docs/resources/lb.md

+15-16
Original file line numberDiff line numberDiff line change
@@ -28,40 +28,30 @@ resource "scaleway_lb" "base" {
2828
### Multiple configurations
2929

3030
```hcl
31-
### IP for LB IP
32-
resource scaleway_lb_ip ip01 {
33-
}
34-
3531
### IP for Public Gateway
3632
resource "scaleway_vpc_public_gateway_ip" "main" {
3733
}
3834
3935
### Scaleway Private Network
4036
resource scaleway_vpc_private_network main {
41-
name = "private network with static config"
4237
}
4338
44-
### The Public Gateway with the Attached IP
39+
### VPC Public Gateway Network
4540
resource "scaleway_vpc_public_gateway" "main" {
4641
name = "tf-test-public-gw"
4742
type = "VPC-GW-S"
4843
ip_id = scaleway_vpc_public_gateway_ip.main.id
4944
}
5045
51-
### Scaleway Private Network
52-
resource "scaleway_vpc_private_network" "pn" {
53-
name = "private network with a DHCP config"
54-
}
55-
56-
### DHCP Space of VPC
46+
### VPC Public Gateway Network DHCP config
5747
resource "scaleway_vpc_public_gateway_dhcp" "main" {
5848
subnet = "10.0.0.0/24"
5949
}
6050
6151
### VPC Gateway Network
6252
resource "scaleway_vpc_gateway_network" "main" {
6353
gateway_id = scaleway_vpc_public_gateway.main.id
64-
private_network_id = scaleway_vpc_private_network.pn.id
54+
private_network_id = scaleway_vpc_private_network.main.id
6555
dhcp_id = scaleway_vpc_public_gateway_dhcp.main.id
6656
cleanup_dhcp = true
6757
enable_masquerade = true
@@ -75,23 +65,32 @@ resource "scaleway_instance_server" "main" {
7565
enable_ipv6 = false
7666
7767
private_network {
78-
pn_id = scaleway_vpc_private_network.pn.id
68+
pn_id = scaleway_vpc_private_network.main.id
7969
}
8070
}
8171
72+
### IP for LB IP
73+
resource scaleway_lb_ip ip01 {
74+
}
75+
76+
### Scaleway Private Network
77+
resource scaleway_vpc_private_network "static" {
78+
name = "private network with static config"
79+
}
8280
81+
### Scaleway Load Balancer
8382
resource scaleway_lb lb01 {
8483
ip_id = scaleway_lb_ip.ip01.id
8584
name = "test-lb-with-private-network-configs"
8685
type = "LB-S"
8786
8887
private_network {
89-
private_network_id = scaleway_vpc_private_network.main.id
88+
private_network_id = scaleway_vpc_private_network.static.id
9089
static_config = ["172.16.0.100", "172.16.0.101"]
9190
}
9291
9392
private_network {
94-
private_network_id = scaleway_vpc_private_network.pn.id
93+
private_network_id = scaleway_vpc_private_network.main.id
9594
dhcp_config = true
9695
}
9796

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ require (
5454
github.com/mitchellh/copystructure v1.2.0 // indirect
5555
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
5656
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
57-
github.com/mitchellh/mapstructure v1.4.3 // indirect
57+
github.com/mitchellh/mapstructure v1.5.0 // indirect
5858
github.com/mitchellh/reflectwalk v1.0.2 // indirect
5959
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
6060
github.com/oklog/run v1.1.0 // indirect
@@ -69,7 +69,7 @@ require (
6969
github.com/zclconf/go-cty v1.10.0 // indirect
7070
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
7171
golang.org/x/net v0.0.0-20220412020605-290c469a71a5 // indirect
72-
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
72+
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 // indirect
7373
golang.org/x/text v0.3.7 // indirect
7474
google.golang.org/appengine v1.6.7 // indirect
7575
google.golang.org/genproto v0.0.0-20220413183235-5e96e2839df9 // indirect

go.sum

+4-3
Original file line numberDiff line numberDiff line change
@@ -717,8 +717,9 @@ github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS4
717717
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
718718
github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
719719
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
720-
github.com/mitchellh/mapstructure v1.4.3 h1:OVowDSCllw/YjdLkam3/sm7wEtOy59d8ndGgCcyj8cs=
721720
github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
721+
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
722+
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
722723
github.com/mitchellh/osext v0.0.0-20151018003038-5e2d6d41470f/go.mod h1:OkQIRizQZAeMln+1tSwduZz7+Af5oFlKirV/MSYes2A=
723724
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
724725
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
@@ -1276,8 +1277,8 @@ golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBc
12761277
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
12771278
golang.org/x/sys v0.0.0-20211116061358-0a5406a5449c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
12781279
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1279-
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0=
1280-
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1280+
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 h1:xHms4gcpe1YE7A3yIllJXP16CMAGuqwO2lX1mTyyRRc=
1281+
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
12811282
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
12821283
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
12831284
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=

scaleway/resource_lb_test.go

+23-29
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ func TestAccScalewayLbLb_WithIP(t *testing.T) {
265265
})
266266
}
267267

268-
func TestAccScalewayLbLb_WithSeveralPrivateNetworks(t *testing.T) {
268+
func TestAccScalewayLbLb_WithPrivateNetworksOnDHCPConfig(t *testing.T) {
269269
tt := NewTestTools(t)
270270
defer tt.Cleanup()
271271
resource.ParallelTest(t, resource.TestCase{
@@ -284,32 +284,31 @@ func TestAccScalewayLbLb_WithSeveralPrivateNetworks(t *testing.T) {
284284
Steps: []resource.TestStep{
285285
{
286286
Config: `
287-
resource "scaleway_vpc_private_network" dhcp_network {
288-
name = "private network with a DHCP config"
289-
}
290-
291-
resource scaleway_vpc_private_network static_network {
292-
name = "private network with static config"
293-
}
294-
295-
287+
### IP for Public Gateway
296288
resource "scaleway_vpc_public_gateway_ip" "main" {
297289
}
298290
291+
### The Public Gateway with the Attached IP
299292
resource "scaleway_vpc_public_gateway" "main" {
300293
name = "tf-test-public-gw"
301294
type = "VPC-GW-S"
302295
ip_id = scaleway_vpc_public_gateway_ip.main.id
303296
}
304297
298+
### Scaleway Private Network
299+
resource "scaleway_vpc_private_network" "main" {
300+
name = "private network with a DHCP config"
301+
}
302+
303+
### DHCP Space of VPC
305304
resource "scaleway_vpc_public_gateway_dhcp" "main" {
306305
subnet = "10.0.0.0/24"
307306
}
308307
309308
### VPC Gateway Network
310309
resource "scaleway_vpc_gateway_network" "main" {
311310
gateway_id = scaleway_vpc_public_gateway.main.id
312-
private_network_id = scaleway_vpc_private_network.dhcp_network.id
311+
private_network_id = scaleway_vpc_private_network.main.id
313312
dhcp_id = scaleway_vpc_public_gateway_dhcp.main.id
314313
cleanup_dhcp = true
315314
enable_masquerade = true
@@ -323,27 +322,21 @@ func TestAccScalewayLbLb_WithSeveralPrivateNetworks(t *testing.T) {
323322
enable_ipv6 = false
324323
325324
private_network {
326-
pn_id = scaleway_vpc_private_network.dhcp_network.id
325+
pn_id = scaleway_vpc_private_network.main.id
327326
}
328-
329-
depends_on = [scaleway_vpc_private_network.dhcp_network]
330327
}
331328
329+
### IP for LB IP
332330
resource scaleway_lb_ip ip01 {
333331
}
334-
332+
335333
resource scaleway_lb lb01 {
336334
ip_id = scaleway_lb_ip.ip01.id
337335
name = "test-lb-with-private-network-configs"
338336
type = "LB-S"
339337
340338
private_network {
341-
private_network_id = scaleway_vpc_private_network.static_network.id
342-
static_config = ["172.16.0.100", "172.16.0.101"]
343-
}
344-
345-
private_network {
346-
private_network_id = scaleway_vpc_private_network.dhcp_network.id
339+
private_network_id = scaleway_vpc_private_network.main.id
347340
dhcp_config = true
348341
}
349342
@@ -353,18 +346,19 @@ func TestAccScalewayLbLb_WithSeveralPrivateNetworks(t *testing.T) {
353346
Check: resource.ComposeTestCheckFunc(
354347
testAccCheckScalewayLbExists(tt, "scaleway_lb.lb01"),
355348
testAccCheckScalewayLbIPExists(tt, "scaleway_lb_ip.ip01"),
356-
resource.TestCheckResourceAttrSet("scaleway_vpc_private_network.dhcp_network", "name"),
357-
resource.TestCheckResourceAttrSet("scaleway_vpc_private_network.static_network", "name"),
358-
resource.TestCheckResourceAttr("scaleway_lb.lb01",
359-
"private_network.0.static_config.0", "172.16.0.100"),
360-
resource.TestCheckResourceAttr("scaleway_lb.lb01",
361-
"private_network.0.static_config.1", "172.16.0.101"),
349+
resource.TestCheckResourceAttrSet("scaleway_vpc_private_network.main", "name"),
350+
resource.TestCheckResourceAttrPair(
351+
"scaleway_lb.lb01", "private_network.0.private_network_id",
352+
"scaleway_vpc_private_network.main", "id"),
353+
resource.TestCheckResourceAttrPair(
354+
"scaleway_instance_server.main", "private_network.0.pn_id",
355+
"scaleway_vpc_private_network.main", "id"),
362356
resource.TestCheckResourceAttr("scaleway_lb.lb01",
363357
"private_network.0.status", lbSDK.PrivateNetworkStatusReady.String()),
364358
resource.TestCheckResourceAttr("scaleway_lb.lb01",
365-
"private_network.1.dhcp_config", "true"),
359+
"private_network.0.dhcp_config", "true"),
366360
resource.TestCheckResourceAttr("scaleway_lb.lb01",
367-
"private_network.1.status", lbSDK.PrivateNetworkStatusReady.String()),
361+
"private_network.0.status", lbSDK.PrivateNetworkStatusReady.String()),
368362
),
369363
},
370364
},

scaleway/resource_vpc_gateway_network_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ func TestAccScalewayVPCGatewayNetwork_Basic(t *testing.T) {
9696
`,
9797
Check: resource.ComposeTestCheckFunc(
9898
testAccCheckScalewayVPCGatewayNetworkExists(tt, "scaleway_vpc_gateway_network.main"),
99+
resource.TestCheckResourceAttrPair("scaleway_vpc_gateway_network.main",
100+
"private_network_id", "scaleway_vpc_private_network.pn01", "id"),
99101
resource.TestCheckResourceAttrSet("scaleway_vpc_gateway_network.main", "gateway_id"),
100102
resource.TestCheckResourceAttrSet("scaleway_vpc_gateway_network.main", "private_network_id"),
101103
resource.TestCheckResourceAttrSet("scaleway_vpc_gateway_network.main", "dhcp_id"),

0 commit comments

Comments
 (0)