Skip to content

Commit f7b8593

Browse files
committed
feat(rdb): add docs and split dhcp test
1 parent 395173f commit f7b8593

12 files changed

+6565
-608457
lines changed

docs/resources/rdb_instance.md

+54-5
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,40 @@ resource "scaleway_rdb_instance" "main" {
3838
backup_schedule_retention = 7 # keep it one week
3939
}
4040
41-
# with private network
42-
resource scaleway_vpc_private_network pn01 {
41+
# with private network and dhcp configuration
42+
resource scaleway_vpc_private_network pn02 {
4343
name = "my_private_network"
44-
tags = ["tag0", "tag1", "rdb_pn"]
44+
}
45+
46+
resource scaleway_vpc_public_gateway_dhcp main {
47+
subnet = "192.168.1.0/24"
48+
}
49+
50+
resource scaleway_vpc_public_gateway_ip main {
51+
}
52+
53+
resource scaleway_vpc_public_gateway main {
54+
name = "foobar"
55+
type = "VPC-GW-S"
56+
ip_id = scaleway_vpc_public_gateway_ip.main.id
57+
}
58+
59+
resource scaleway_vpc_public_gateway_pat_rule main {
60+
gateway_id = scaleway_vpc_public_gateway.main.id
61+
private_ip = scaleway_vpc_public_gateway_dhcp.main.address
62+
private_port = scaleway_rdb_instance.main.private_network.0.port
63+
public_port = 42
64+
protocol = "both"
65+
depends_on = [scaleway_vpc_gateway_network.main, scaleway_vpc_private_network.pn02]
66+
}
67+
68+
resource scaleway_vpc_gateway_network main {
69+
gateway_id = scaleway_vpc_public_gateway.main.id
70+
private_network_id = scaleway_vpc_private_network.pn02.id
71+
dhcp_id = scaleway_vpc_public_gateway_dhcp.main.id
72+
cleanup_dhcp = true
73+
enable_masquerade = true
74+
depends_on = [scaleway_vpc_public_gateway_ip.main, scaleway_vpc_private_network.pn02]
4575
}
4676
4777
resource scaleway_rdb_instance main {
@@ -57,8 +87,8 @@ resource scaleway_rdb_instance main {
5787
volume_type = "bssd"
5888
volume_size_in_gb = 10
5989
private_network {
60-
ip = "192.168.1.42/24"
61-
pn_id = "${scaleway_vpc_private_network.pn01.id}"
90+
ip_net = "192.168.1.254/24" #pool high
91+
pn_id = "${scaleway_vpc_private_network.pn02.id}"
6292
}
6393
}
6494
```
@@ -105,6 +135,13 @@ The following arguments are supported:
105135

106136
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the Database Instance is associated with.
107137

138+
## Private Network
139+
140+
~> **Important:** Updates to `private_network` will recreate the attachment Instance.
141+
142+
- `ip_net` - (Required) The IP network where to con.
143+
- `pn_id` - (Required) The ID of the private network. If not provided it will be randomly generated.
144+
108145
## Attributes Reference
109146

110147
In addition to all arguments above, the following attributes are exported:
@@ -116,6 +153,18 @@ In addition to all arguments above, the following attributes are exported:
116153
- `ip` - IP of the replica.
117154
- `port` - Port of the replica.
118155
- `name` - Name of the replica.
156+
- `load_balancer` - List of load balancer endpoints of the database instance.
157+
- `endpoint_id` - The ID of the endpoint of the load balancer.
158+
- `ip` - IP of the endpoint.
159+
- `port` - Port of the endpoint.
160+
- `name` - Name of the endpoint.
161+
- `hostname` - Name of the endpoint.
162+
- `private_network` - List of private networks endpoints of the database instance.
163+
- `endpoint_id` - The ID of the endpoint of the private network.
164+
- `ip` - IP of the endpoint.
165+
- `port` - Port of the endpoint.
166+
- `name` - Name of the endpoint.
167+
- `hostname` - Name of the endpoint.
119168
- `certificate` - Certificate of the database instance.
120169
- `organization_id` - The organization ID the Database Instance is associated with.
121170

scaleway/helpers_rdb_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func TestEndpointsToRemove(t *testing.T) {
8585
IP: net.IPv4(1, 1, 1, 1), Mask: net.CIDRMask(24, 32)}},
8686
Zone: scw.ZoneFrPar1},
8787
}},
88-
Updates: []interface{}{map[string]interface{}{"pn_id": "fr-par-1/6ba7b810-9dad-11d1-80b4-00c04fd430c8", "ip": "192.168.1.43/24"}},
88+
Updates: []interface{}{map[string]interface{}{"pn_id": "fr-par-1/6ba7b810-9dad-11d1-80b4-00c04fd430c8", "ip_net": "192.168.1.43/24"}},
8989
Expected: map[string]bool{
9090
"6ba7b810-9dad-11d1-80b4-00c04fd430c1": true,
9191
},
@@ -99,14 +99,14 @@ func TestEndpointsToRemove(t *testing.T) {
9999
IP: net.IPv4(1, 1, 1, 1), Mask: net.CIDRMask(24, 32)}},
100100
Zone: scw.ZoneFrPar1},
101101
}},
102-
Updates: []interface{}{map[string]interface{}{"pn_id": "fr-par-1/6ba7b810-9dad-11d1-80b4-00c04fd430c8", "ip": "1.1.1.1/24"}},
102+
Updates: []interface{}{map[string]interface{}{"pn_id": "fr-par-1/6ba7b810-9dad-11d1-80b4-00c04fd430c8", "ip_net": "1.1.1.1/24"}},
103103
Expected: map[string]bool{
104104
"6ba7b810-9dad-11d1-80b4-00c04fd430c1": false,
105105
},
106106
},
107107
{
108108
name: "shouldAddPrivateNetwork",
109-
Updates: []interface{}{map[string]interface{}{"pn_id": "fr-par-1/6ba7b810-9dad-11d1-80b4-00c04fd430c8", "ip": "1.1.1.1/24"}},
109+
Updates: []interface{}{map[string]interface{}{"pn_id": "fr-par-1/6ba7b810-9dad-11d1-80b4-00c04fd430c8", "ip_net": "1.1.1.1/24"}},
110110
Expected: map[string]bool{},
111111
},
112112
}

scaleway/resource_rdb_instance.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func resourceScalewayRdbInstance() *schema.Resource {
129129
Type: schema.TypeString,
130130
Required: true,
131131
ValidateFunc: validation.IsCIDR,
132-
Description: "The subnet of your private network",
132+
Description: "The ip net of your private network",
133133
},
134134
"pn_id": {
135135
Type: schema.TypeString,

scaleway/resource_rdb_instance_test.go

+61-22
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,16 @@ func TestAccScalewayRdbInstance_PrivateNetwork(t *testing.T) {
306306
ip_id = scaleway_vpc_public_gateway_ip.main.id
307307
}
308308
309+
resource scaleway_vpc_public_gateway_pat_rule main {
310+
gateway_id = scaleway_vpc_public_gateway.main.id
311+
private_ip = scaleway_vpc_public_gateway_dhcp.main.address
312+
private_port = scaleway_rdb_instance.main.private_network.0.port
313+
public_port = 42
314+
protocol = "both"
315+
zone = "nl-ams-1"
316+
depends_on = [scaleway_vpc_gateway_network.main, scaleway_vpc_private_network.pn02]
317+
}
318+
309319
resource scaleway_vpc_gateway_network main {
310320
gateway_id = scaleway_vpc_public_gateway.main.id
311321
private_network_id = scaleway_vpc_private_network.pn02.id
@@ -339,6 +349,26 @@ func TestAccScalewayRdbInstance_PrivateNetwork(t *testing.T) {
339349
resource.TestCheckResourceAttr("scaleway_rdb_instance.main", "private_network.0.ip_net", "192.168.1.254/24"),
340350
),
341351
},
352+
{
353+
Config: `
354+
resource scaleway_vpc_private_network pn02 {
355+
name = "my_private_network"
356+
zone = "nl-ams-1"
357+
}
358+
`,
359+
},
360+
},
361+
})
362+
}
363+
364+
func TestAccScalewayRdbInstance_PrivateNetwork_DHCP(t *testing.T) {
365+
tt := NewTestTools(t)
366+
defer tt.Cleanup()
367+
resource.ParallelTest(t, resource.TestCase{
368+
PreCheck: func() { testAccPreCheck(t) },
369+
ProviderFactories: tt.ProviderFactories,
370+
CheckDestroy: testAccCheckScalewayRdbInstanceDestroy(tt),
371+
Steps: []resource.TestStep{
342372
{
343373
Config: `
344374
resource scaleway_vpc_private_network pn02 {
@@ -362,6 +392,16 @@ func TestAccScalewayRdbInstance_PrivateNetwork(t *testing.T) {
362392
ip_id = scaleway_vpc_public_gateway_ip.main.id
363393
}
364394
395+
resource scaleway_vpc_public_gateway_pat_rule main {
396+
gateway_id = scaleway_vpc_public_gateway.main.id
397+
private_ip = scaleway_vpc_public_gateway_dhcp.main.address
398+
private_port = scaleway_rdb_instance.main.private_network.0.port
399+
public_port = 42
400+
protocol = "both"
401+
zone = "nl-ams-1"
402+
depends_on = [scaleway_vpc_gateway_network.main, scaleway_vpc_private_network.pn02]
403+
}
404+
365405
resource scaleway_vpc_gateway_network main {
366406
gateway_id = scaleway_vpc_public_gateway.main.id
367407
private_network_id = scaleway_vpc_private_network.pn02.id
@@ -371,35 +411,34 @@ func TestAccScalewayRdbInstance_PrivateNetwork(t *testing.T) {
371411
zone = "nl-ams-1"
372412
depends_on = [scaleway_vpc_public_gateway_ip.main, scaleway_vpc_private_network.pn02]
373413
}
374-
`,
375-
},
376-
{
377-
Config: `
378-
resource scaleway_vpc_private_network pn02 {
379-
name = "my_private_network_without_attachment"
380-
zone = "nl-ams-1"
381-
}
382414
383-
resource scaleway_vpc_public_gateway_ip main {
384-
zone = "nl-ams-1"
385-
}
386-
387-
resource scaleway_vpc_public_gateway main {
388-
name = "foobar"
389-
type = "VPC-GW-S"
390-
zone = "nl-ams-1"
391-
ip_id = scaleway_vpc_public_gateway_ip.main.id
415+
resource scaleway_rdb_instance main {
416+
name = "test-rdb"
417+
node_type = "db-dev-s"
418+
engine = "PostgreSQL-11"
419+
is_ha_cluster = false
420+
disable_backup = true
421+
user_name = "my_initial_user"
422+
password = "thiZ_is_v&ry_s3cret"
423+
region= "nl-ams"
424+
tags = [ "terraform-test", "scaleway_rdb_instance", "volume", "rdb_pn" ]
425+
volume_type = "bssd"
426+
volume_size_in_gb = 10
427+
private_network {
428+
ip_net = "192.168.1.254/24" #pool high
429+
pn_id = "${scaleway_vpc_private_network.pn02.id}"
430+
}
392431
}
393432
`,
433+
Check: resource.ComposeTestCheckFunc(
434+
testAccCheckScalewayRdbExists(tt, "scaleway_rdb_instance.main"),
435+
resource.TestCheckResourceAttr("scaleway_rdb_instance.main", "private_network.0.ip_net", "192.168.1.254/24"),
436+
),
394437
},
395438
{
396439
Config: `
397440
resource scaleway_vpc_private_network pn02 {
398-
name = "my_private_network_without_attachment"
399-
zone = "nl-ams-1"
400-
}
401-
402-
resource scaleway_vpc_public_gateway_ip main {
441+
name = "my_private_network"
403442
zone = "nl-ams-1"
404443
}
405444
`,

0 commit comments

Comments
 (0)