Skip to content

Commit 9871d05

Browse files
scaleway-botMonitob
authored andcommitted
feat(rdb): private_network test
1 parent aa58cfe commit 9871d05

File tree

62 files changed

+1044600
-4122
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1044600
-4122
lines changed

docs/resources/lb.md

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ resource "scaleway_lb" "base" {
2121
ip_id = scaleway_lb_ip.ip.id
2222
zone = "fr-par-1"
2323
type = "LB-S"
24+
release_ip = true
2425
}
2526
```
2627

@@ -40,6 +41,8 @@ The following arguments are supported:
4041

4142
- `tags` - (Optional) The tags associated with the load-balancers.
4243

44+
- `release_ip` - (Defaults to false) The release_ip allow release the ip address associated with the load-balancers.
45+
4346
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the IP should be reserved.
4447

4548
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the load-balancer is associated with.
@@ -77,6 +80,7 @@ resource "scaleway_lb" "base" {
7780
ip_id = scaleway_lb_ip.ip.id
7881
zone = "fr-par-1"
7982
type = "LB-S"
83+
release_ip = true
8084
}
8185
```
8286

docs/resources/lb_backend.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ The following arguments are supported:
5050
- `forward_port` - (Required) User sessions will be forwarded to this port of backend servers.
5151
- `forward_port_algorithm` - (Default: `roundrobin`) Load balancing algorithm. Possible values are: `roundrobin`, `leastconn` and `first`.
5252
- `sticky_sessions` - (Default: `none`) Load balancing algorithm. Possible values are: `none`, `cookie` and `table`.
53-
- `sticky_sessions_cookie_name` - (Optional) Cookie name for for sticky sessions. Only applicable when sticky_sessions is set to `cookie`.
53+
- `sticky_sessions_cookie_name` - (Optional) Cookie name for sticky sessions. Only applicable when sticky_sessions is set to `cookie`.
5454
- `server_ips` - (Optional) List of backend server IP addresses. Addresses can be either IPv4 or IPv6.
5555
- `send_proxy_v2` - DEPRECATED please use `proxy_protocol` instead - (Default: `false`) Enables PROXY protocol version 2.
5656
- `proxy_protocol` - (Default: `none`) Choose the type of PROXY protocol to enable (`none`, `v1`, `v2`, `v2_ssl`, `v2_ssl_cn`)

docs/resources/lb_private_network.md

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
page_title: "Scaleway: scaleway_lb_private_network"
3+
description: |-
4+
Manages Scaleway Load-Balancers private networks
5+
---
6+
7+
# scaleway_lb_private_network
8+
9+
Creates and manages Scaleway attach/detach private networks to Load-Balancers.
10+
For more information, see [the documentation](https://developers.scaleway.com/en/products/lb/zoned_api/#post-d4b30).
11+
12+
## Examples
13+
14+
### Basic
15+
16+
```hcl
17+
resource scaleway_vpc_private_network pn01 {
18+
name = "test-lb-pn"
19+
}
20+
21+
resource scaleway_lb_ip ip01 {}
22+
23+
resource scaleway_lb lb01 {
24+
ip_id = scaleway_lb_ip.ip01.id
25+
name = "test-lb"
26+
type = "lb-s"
27+
release_ip = true
28+
}
29+
30+
resource scaleway_lb_private_network lb01pn01 {
31+
lb_id = scaleway_lb.lb01.id
32+
private_network_id = scaleway_vpc_private_network.pn01.id
33+
static_config = ["172.16.0.100", "172.16.0.101"]
34+
}
35+
```
36+
37+
## Arguments Reference
38+
39+
The following arguments are supported:
40+
41+
- `lb_id` - (Required) The ID of the load-balancer to associate.
42+
43+
- `private_network_id` - (Required) The ID of the Private Network to associate.
44+
45+
- `static_config` - (Required) Define two local ip address of your choice for each load balancer instance. See below.
46+
47+
- `dhcp_config` - (Required) Set to true if you want to let DHCP assign IP addresses. See below.
48+
49+
~> **Important:** Only one of static_config and dhcp_config may be set.
50+
51+
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the IP should be reserved.
52+
53+
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the load-balancer is associated with.
54+
55+
## Attributes Reference
56+
57+
In addition to all arguments above, the following attributes are exported:
58+
59+
- `status` - The Private Network attachment status
60+
61+
## Import
62+
63+
Load-Balancer private network can be imported using the `{zone}/{id}`, e.g.
64+
65+
```bash
66+
$ terraform import scaleway_lb_private_network.lb01pn01 fr-par/11111111-1111-1111-1111-111111111111
67+
```
68+
69+
The attachments can either be found in the console

docs/resources/rdb_instance.md

+25-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ resource "scaleway_rdb_instance" "main" {
2323
user_name = "my_initial_user"
2424
password = "thiZ_is_v&ry_s3cret"
2525
}
26+
27+
# with backup schedule
28+
resource "scaleway_rdb_instance" "main" {
29+
name = "test-rdb"
30+
node_type = "DB-DEV-S"
31+
engine = "PostgreSQL-11"
32+
is_ha_cluster = true
33+
user_name = "my_initial_user"
34+
password = "thiZ_is_v&ry_s3cret"
35+
36+
disable_backup = true
37+
backup_schedule_frequency = 24 # every day
38+
backup_schedule_retention = 7 # keep it one week
39+
}
2640
```
2741

2842
## Arguments Reference
@@ -55,11 +69,21 @@ The following arguments are supported:
5569

5670
- `disable_backup` - (Optional) Disable automated backup for the database instance.
5771

72+
- `backup_schedule_frequency` - (Optional) Backup schedule frequency in hours.
73+
74+
- `backup_schedule_retention` - (Optional) Backup schedule retention in days.
75+
5876
- `settings` - Map of engine settings to be set.
5977

6078
- `tags` - (Optional) The tags associated with the Database Instance.
6179

62-
- `region` - (Defaults to [provider](../index.md#region) `region`) The [region](../guides/regions_and_zones.md#regions) in which the Database Instance should be created.
80+
- `private_network` - (Optional) The private_network associated with the Database Instance.
81+
82+
The `private_network` block supports:
83+
84+
- `ip` - (Required) The ip range to assign to my instance in [CIDR notation](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation)
85+
- `pn_id` - (Required) The private_network ID in which the Database Instance should be connected.
86+
- The private network should be created in the same region and locality.
6387

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

docs/resources/vpc_gateway_network.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ The following arguments are supported:
4444
- `gateway_id` - (Required) The ID of the public gateway.
4545
- `private_network_id` - (Required) The ID of the private network.
4646
- `dhcp_id` - (Required) The ID of the public gateway DHCP config.
47-
- `enable_masquerade` - (Defaults to false) Enable masquerade on this network
47+
- `enable_masquerade` - (Defaults to true) Enable masquerade on this network
4848
- `enable_dhcp` - (Defaults to true) Enable DHCP config on this network. It requires DHCP id.
49+
- `cleanup_dhcp` - (Defaults to false) Remove DHCP config on this network on destroy. It requires DHCP id.
4950
- `static_address` - Enable DHCP config on this network
5051
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the gateway network should be created.
5152
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the gateway network is associated with.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
page_title: "Scaleway: scaleway_vpc_public_gateway_pat_rule"
3+
description: |-
4+
Manages Scaleway VPC Public Gateways PAT rules.
5+
---
6+
7+
# scaleway_vpc_public_gateway_pat_rule
8+
9+
Creates and manages Scaleway VPC Public Gateway PAT (Port Address Translation).
10+
For more information, see [the documentation](https://developers.scaleway.com/en/products/vpc-gw/api/#pat-rules-e75d10).
11+
12+
## Example
13+
14+
```hcl
15+
resource scaleway_vpc_public_gateway pg01 {
16+
type = "VPC-GW-S"
17+
}
18+
19+
resource scaleway_vpc_public_gateway_dhcp dhcp01 {
20+
subnet = "192.168.1.0/24"
21+
}
22+
23+
resource scaleway_vpc_private_network pn01 {
24+
name = "pn_test_network"
25+
}
26+
27+
resource scaleway_vpc_gateway_network gn01 {
28+
gateway_id = scaleway_vpc_public_gateway.pg01.id
29+
private_network_id = scaleway_vpc_private_network.pn01.id
30+
dhcp_id = scaleway_vpc_public_gateway_dhcp.dhcp01.id
31+
cleanup_dhcp = true
32+
}
33+
34+
resource scaleway_vpc_public_gateway_pat_rule main {
35+
gateway_id = scaleway_vpc_public_gateway.pg01.id
36+
private_ip = scaleway_vpc_public_gateway_dhcp.dhcp01.address
37+
private_port = 42
38+
public_port = 42
39+
protocol = "both"
40+
depends_on = [scaleway_vpc_gateway_network.gn01, scaleway_vpc_private_network.pn01]
41+
}
42+
```
43+
44+
## Arguments Reference
45+
46+
The following arguments are supported:
47+
48+
- `gateway_id` - (Required) The ID of the public gateway.
49+
- `private_ip` - (Required) The Private IP to forward data to (IP address).
50+
- `public_port` - (Required) The Public port to listen on.
51+
- `private_port` - (Required) The Private port to translate to.
52+
- `protocol` - (Defaults to both) The Protocol the rule should apply to. Possible values are both, tcp and udp.
53+
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the public gateway DHCP config should be created.
54+
55+
## Attributes Reference
56+
57+
In addition to all above arguments, the following attributes are exported:
58+
59+
- `id` - The ID of the public gateway DHCP config.
60+
- `organization_id` - The organization ID the pat rule config is associated with.
61+
- `created_at` - The date and time of the creation of the pat rule config.
62+
- `updated_at` - The date and time of the last update of the pat rule config.
63+
64+
## Import
65+
66+
Public gateway PAT rules config can be imported using the `{zone}/{id}`, e.g.
67+
68+
```bash
69+
$ terraform import scaleway_vpc_public_gateway_pat_rule.main fr-par-1/11111111-1111-1111-1111-111111111111
70+
```

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
module github.com/scaleway/terraform-provider-scaleway
22

33
require (
4-
github.com/aws/aws-sdk-go v1.41.1
4+
github.com/aws/aws-sdk-go v1.41.8
55
github.com/dnaeon/go-vcr v1.2.0
66
github.com/dustin/go-humanize v1.0.0
77
github.com/google/go-cmp v0.5.6
88
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
99
github.com/hashicorp/go-retryablehttp v0.7.0
1010
github.com/hashicorp/terraform-plugin-sdk/v2 v2.8.0
11-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7.0.20211005125957-db499d89a262
11+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7.0.20211012131628-5b68cc2973b3
1212
github.com/stretchr/testify v1.7.0
1313
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
1414

go.sum

+4-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj
6262
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
6363
github.com/aws/aws-sdk-go v1.15.78/go.mod h1:E3/ieXAlvM0XWO57iftYVDLLvQ824smPP3ATZkfNZeM=
6464
github.com/aws/aws-sdk-go v1.25.3/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
65-
github.com/aws/aws-sdk-go v1.41.1 h1:TR9j7i73tzV8ELPMc0LkImSRLljRJ+gQeArKBC7IfVE=
66-
github.com/aws/aws-sdk-go v1.41.1/go.mod h1:585smgzpB/KqRA+K3y/NL/oYRqQvpNJYvLm+LY1U59Q=
65+
github.com/aws/aws-sdk-go v1.41.8 h1:j6imzwVyWQYuQxbkPmg2MdMmLB+Zw+U3Ewi59YF8Rwk=
66+
github.com/aws/aws-sdk-go v1.41.8/go.mod h1:585smgzpB/KqRA+K3y/NL/oYRqQvpNJYvLm+LY1U59Q=
6767
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas=
6868
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4=
6969
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
@@ -286,6 +286,8 @@ github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:
286286
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
287287
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7.0.20211005125957-db499d89a262 h1:ioN4zmp/4AoCJ/BbuwmkpH+bnSSntgWMUN1PkQ46/nI=
288288
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7.0.20211005125957-db499d89a262/go.mod h1:NnxccdAsg2lS0ng/kfLVLemUQR50FCM/cdZv2gqKDhw=
289+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7.0.20211012131628-5b68cc2973b3 h1:PhWAnBbS6rWqa4A4KVCAda5ry9o2Tk3kOVjBw3DvW9s=
290+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7.0.20211012131628-5b68cc2973b3/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
289291
github.com/sebdah/goldie v1.0.0/go.mod h1:jXP4hmWywNEwZzhMuv2ccnqTSFpuq8iyQhtQdkkZBH4=
290292
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
291293
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=

scaleway/data_source_lb.go

+16
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ func dataSourceScalewayLb() *schema.Resource {
2525
ValidateFunc: validationUUIDorUUIDWithLocality(),
2626
ConflictsWith: []string{"name"},
2727
}
28+
dsSchema["release_ip"] = &schema.Schema{
29+
Type: schema.TypeBool,
30+
Optional: true,
31+
Default: false,
32+
Description: "Release the IPs related to this load-balancer",
33+
}
2834

2935
return &schema.Resource{
3036
ReadContext: dataSourceScalewayLbRead,
@@ -57,6 +63,16 @@ func dataSourceScalewayLbRead(ctx context.Context, d *schema.ResourceData, meta
5763
lbID = res.LBs[0].ID
5864
}
5965

66+
var relaseIPValue bool
67+
releaseIPAddress, releaseIPExist := d.GetOk("release_ip")
68+
if releaseIPExist {
69+
relaseIPValue = *expandBoolPtr(releaseIPAddress)
70+
}
71+
72+
err = d.Set("release_ip", relaseIPValue)
73+
if err != nil {
74+
return diag.FromErr(err)
75+
}
6076
zonedID := datasourceNewZonedID(lbID, zone)
6177
d.SetId(zonedID)
6278
err = d.Set("lb_id", zonedID)

scaleway/helpers.go

+5
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ func is404Error(err error) bool {
229229
return isHTTPCodeError(err, http.StatusNotFound) || xerrors.As(err, &notFoundError)
230230
}
231231

232+
func is412Error(err error) bool {
233+
preConditionFailedError := &scw.PreconditionFailedError{}
234+
return isHTTPCodeError(err, http.StatusPreconditionFailed) || xerrors.As(err, &preConditionFailedError)
235+
}
236+
232237
// is403Error returns true if err is an HTTP 403 error
233238
func is403Error(err error) bool {
234239
permissionsDeniedError := &scw.PermissionsDeniedError{}

scaleway/helpers_domain.go

+11-10
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ func flattenDomainData(data string, recordType domain.RecordType) interface{} {
3434
}
3535

3636
func flattenDomainGeoIP(config *domain.RecordGeoIPConfig) interface{} {
37-
flattened := []map[string]interface{}{}
37+
var flattened []map[string]interface{}
3838

3939
if config == nil {
4040
return flattened
4141
}
4242

4343
flattened = []map[string]interface{}{{}}
4444
if config.Matches != nil && len(config.Matches) > 0 {
45-
matches := []map[string]interface{}{}
45+
var matches []map[string]interface{}
4646
for _, match := range config.Matches {
4747
rawMatch := map[string]interface{}{
4848
"data": match.Data,
@@ -78,7 +78,8 @@ func expandDomainGeoIPConfig(defaultData string, i interface{}, ok bool) *domain
7878
return &config
7979
}
8080

81-
matches := []*domain.RecordGeoIPConfigMatch{}
81+
var matches []*domain.RecordGeoIPConfigMatch
82+
8283
for _, rawMatch := range rawMatches {
8384
rawMatchMap := rawMatch.(map[string]interface{})
8485

@@ -109,13 +110,13 @@ func expandDomainGeoIPConfig(defaultData string, i interface{}, ok bool) *domain
109110
}
110111

111112
func flattenDomainHTTPService(config *domain.RecordHTTPServiceConfig) interface{} {
112-
flattened := []map[string]interface{}{}
113+
var flattened []map[string]interface{}
113114

114115
if config == nil {
115116
return flattened
116117
}
117118

118-
ips := []interface{}{}
119+
var ips []interface{}
119120
if config.IPs != nil && len(config.IPs) > 0 {
120121
for _, ip := range config.IPs {
121122
ips = append(ips, ip.String())
@@ -139,7 +140,7 @@ func expandDomainHTTPService(i interface{}, ok bool) *domain.RecordHTTPServiceCo
139140

140141
rawMap := i.([]interface{})[0].(map[string]interface{})
141142

142-
ips := []net.IP{}
143+
var ips []net.IP
143144
rawIPs, ok := rawMap["ips"].([]interface{})
144145
if ok {
145146
for _, rawIP := range rawIPs {
@@ -157,7 +158,7 @@ func expandDomainHTTPService(i interface{}, ok bool) *domain.RecordHTTPServiceCo
157158
}
158159

159160
func flattenDomainWeighted(config *domain.RecordWeightedConfig) interface{} {
160-
flattened := []map[string]interface{}{}
161+
var flattened []map[string]interface{}
161162

162163
if config == nil {
163164
return flattened
@@ -182,7 +183,7 @@ func expandDomainWeighted(i interface{}, ok bool) *domain.RecordWeightedConfig {
182183

183184
raw := i.([]interface{})
184185

185-
weightedIPs := []*domain.RecordWeightedConfigWeightedIP{}
186+
var weightedIPs []*domain.RecordWeightedConfigWeightedIP
186187
if len(raw) > 0 {
187188
for _, rawWeighted := range raw {
188189
rawMap := rawWeighted.(map[string]interface{})
@@ -198,7 +199,7 @@ func expandDomainWeighted(i interface{}, ok bool) *domain.RecordWeightedConfig {
198199
}
199200

200201
func flattenDomainView(config *domain.RecordViewConfig) interface{} {
201-
flattened := []map[string]interface{}{}
202+
var flattened []map[string]interface{}
202203

203204
if config == nil {
204205
return flattened
@@ -223,7 +224,7 @@ func expandDomainView(i interface{}, ok bool) *domain.RecordViewConfig {
223224

224225
raw := i.([]interface{})
225226

226-
views := []*domain.RecordViewConfigView{}
227+
var views []*domain.RecordViewConfigView
227228
if len(raw) > 0 {
228229
for _, rawWeighted := range raw {
229230
rawMap := rawWeighted.(map[string]interface{})

0 commit comments

Comments
 (0)