Skip to content

Commit 487d9d6

Browse files
Monitobremyleone
andauthored
fix(rdb-acl): tags, ACL description attribute and documentation (#1180)
Co-authored-by: Rémy Léone <[email protected]>
1 parent bb44129 commit 487d9d6

9 files changed

+1506
-405
lines changed

docs/resources/rdb_acl.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
22
page_title: "Scaleway: scaleway_rdb_acl"
33
description: |-
4-
Manages Scaleway Database Instances.
4+
Manages Scaleway Database ACL rules.
55
---
66

77
# scaleway_rdb_acl
88

9-
Creates and manages Scaleway Database instance autorized IPs.
10-
For more information, see [the documentation](https://developers.scaleway.com/en/products/rdb/api).
9+
Creates and manages Scaleway Database instance authorized IPs.
10+
For more information, see [the documentation](https://developers.scaleway.com/en/products/rdb/api/#acl-rules-allowed-ips).
1111

1212
## Examples
1313

@@ -36,7 +36,7 @@ The following arguments are supported:
3636
The `acl_rules` block supports:
3737

3838
- `ip` - (Required) The ip range to whitelist in [CIDR notation](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation)
39-
- `description` - (Optional) A simple text describing this rule
39+
- `description` - (Optional) A text describing this rule. Default description: `IP allowed`
4040

4141

4242
## Attributes Reference

docs/resources/rdb_instance.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ The following arguments are supported:
149149
In addition to all arguments above, the following attributes are exported:
150150

151151
- `id` - The ID of the Database Instance.
152-
- `endpoint_ip` - The IP of the Database Instance.
153-
- `endpoint_port` - The port of the Database Instance.
152+
- `endpoint_ip` - (Deprecated) The IP of the Database Instance.
153+
- `endpoint_port` - (Deprecated) The port of the Database Instance.
154154
- `read_replicas` - List of read replicas of the database instance.
155155
- `ip` - IP of the replica.
156156
- `port` - Port of the replica.

scaleway/resource_instance_ip.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ func resourceScalewayInstanceIPRead(ctx context.Context, d *schema.ResourceData,
119119
_ = d.Set("organization_id", res.IP.Organization)
120120
_ = d.Set("project_id", res.IP.Project)
121121
_ = d.Set("reverse", res.IP.Reverse)
122-
_ = d.Set("tags", res.IP.Tags)
122+
if len(res.IP.Tags) > 0 {
123+
_ = d.Set("tags", flattenSliceString(res.IP.Tags))
124+
}
123125

124126
if res.IP.Server != nil {
125127
_ = d.Set("server_id", newZonedIDString(res.IP.Zone, res.IP.Server.ID))

scaleway/resource_rdb_acl.go

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func resourceScalewayRdbACL() *schema.Resource {
4646
"description": {
4747
Type: schema.TypeString,
4848
Optional: true,
49+
Computed: true,
4950
Description: "Description of the rule",
5051
},
5152
},

scaleway/resource_rdb_acl_test.go

+32
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,38 @@ func TestAccScalewayRdbACL_Basic(t *testing.T) {
2323
ProviderFactories: tt.ProviderFactories,
2424
CheckDestroy: testAccCheckScalewayRdbInstanceDestroy(tt),
2525
Steps: []resource.TestStep{
26+
{
27+
Config: fmt.Sprintf(`
28+
resource "scaleway_instance_ip" "front1_ip" {
29+
}
30+
31+
resource "scaleway_instance_ip" "front2_ip" {
32+
}
33+
34+
resource scaleway_rdb_instance main {
35+
name = "%s"
36+
node_type = "db-dev-s"
37+
engine = "PostgreSQL-12"
38+
is_ha_cluster = false
39+
}
40+
41+
resource "scaleway_rdb_acl" "main" {
42+
instance_id = scaleway_rdb_instance.main.id
43+
44+
acl_rules {
45+
ip = "${scaleway_instance_ip.front1_ip.address}/32"
46+
}
47+
48+
acl_rules {
49+
ip = "${scaleway_instance_ip.front2_ip.address}/32"
50+
}
51+
}
52+
`, instanceName),
53+
Check: resource.ComposeTestCheckFunc(
54+
resource.TestCheckResourceAttrSet("scaleway_rdb_acl.main", "acl_rules.0.description"),
55+
resource.TestCheckResourceAttrSet("scaleway_rdb_acl.main", "acl_rules.1.description"),
56+
),
57+
},
2658
{
2759
Config: fmt.Sprintf(`
2860
resource scaleway_rdb_instance main {

scaleway/resource_rdb_instance.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ func resourceScalewayRdbInstance() *schema.Resource {
185185
Type: schema.TypeString,
186186
Computed: true,
187187
Description: "Endpoint IP of the database instance",
188+
Deprecated: "Please use the private_network or the load_balancer attribute",
188189
},
189190
"endpoint_port": {
190191
Type: schema.TypeInt,
@@ -286,10 +287,14 @@ func resourceScalewayRdbInstanceCreate(ctx context.Context, d *schema.ResourceDa
286287
DisableBackup: d.Get("disable_backup").(bool),
287288
UserName: d.Get("user_name").(string),
288289
Password: d.Get("password").(string),
289-
Tags: expandStrings(d.Get("tags")),
290290
VolumeType: rdb.VolumeType(d.Get("volume_type").(string)),
291291
}
292292

293+
rawTag, tagExist := d.GetOk("tags")
294+
if tagExist {
295+
createReq.Tags = expandStrings(rawTag)
296+
}
297+
293298
pn, pnExist := d.GetOk("private_network")
294299
if pnExist {
295300
createReq.InitEndpoints, err = expandPrivateNetwork(pn, pnExist)
@@ -387,7 +392,9 @@ func resourceScalewayRdbInstanceRead(ctx context.Context, d *schema.ResourceData
387392
_ = d.Set("backup_same_region", res.BackupSameRegion)
388393
_ = d.Set("user_name", d.Get("user_name").(string)) // user name and
389394
_ = d.Set("password", d.Get("password").(string)) // password are immutable
390-
_ = d.Set("tags", res.Tags)
395+
if len(res.Tags) > 0 {
396+
_ = d.Set("tags", flattenSliceString(res.Tags))
397+
}
391398
if res.Endpoint != nil {
392399
_ = d.Set("endpoint_ip", flattenIPPtr(res.Endpoint.IP))
393400
_ = d.Set("endpoint_port", int(res.Endpoint.Port))

scaleway/resource_rdb_instance_test.go

+31
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,37 @@ func TestAccScalewayRdbInstance_Basic(t *testing.T) {
8383
resource.TestCheckResourceAttrSet("scaleway_rdb_instance.main", "load_balancer.0.port"),
8484
),
8585
},
86+
{
87+
Config: `
88+
resource scaleway_rdb_instance main {
89+
name = "test-rdb-basic"
90+
node_type = "db-dev-s"
91+
engine = "PostgreSQL-11"
92+
is_ha_cluster = false
93+
disable_backup = true
94+
user_name = "my_initial_user"
95+
password = "thiZ_is_v&ry_s3cret"
96+
tags = [ "terraform-change-tag" ]
97+
}
98+
`,
99+
Check: resource.ComposeTestCheckFunc(
100+
testAccCheckScalewayRdbExists(tt, "scaleway_rdb_instance.main"),
101+
resource.TestCheckResourceAttr("scaleway_rdb_instance.main", "name", "test-rdb-basic"),
102+
resource.TestCheckResourceAttr("scaleway_rdb_instance.main", "node_type", "db-dev-s"),
103+
resource.TestCheckResourceAttr("scaleway_rdb_instance.main", "engine", "PostgreSQL-11"),
104+
resource.TestCheckResourceAttr("scaleway_rdb_instance.main", "is_ha_cluster", "false"),
105+
resource.TestCheckResourceAttr("scaleway_rdb_instance.main", "disable_backup", "true"),
106+
resource.TestCheckResourceAttr("scaleway_rdb_instance.main", "user_name", "my_initial_user"),
107+
resource.TestCheckResourceAttr("scaleway_rdb_instance.main", "password", "thiZ_is_v&ry_s3cret"),
108+
resource.TestCheckResourceAttr("scaleway_rdb_instance.main", "tags.0", "terraform-change-tag"),
109+
resource.TestCheckResourceAttrSet("scaleway_rdb_instance.main", "endpoint_ip"),
110+
resource.TestCheckResourceAttrSet("scaleway_rdb_instance.main", "endpoint_port"),
111+
resource.TestCheckResourceAttrSet("scaleway_rdb_instance.main", "certificate"),
112+
resource.TestCheckResourceAttrSet("scaleway_rdb_instance.main", "load_balancer.0.ip"),
113+
resource.TestCheckResourceAttrSet("scaleway_rdb_instance.main", "load_balancer.0.endpoint_id"),
114+
resource.TestCheckResourceAttrSet("scaleway_rdb_instance.main", "load_balancer.0.port"),
115+
),
116+
},
86117
},
87118
})
88119
}

0 commit comments

Comments
 (0)