Skip to content

Commit

Permalink
fix(rdb-acl): tags, ACL description attribute and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Monitob committed Apr 5, 2022
1 parent deaa2c0 commit 7ab8ce0
Show file tree
Hide file tree
Showing 7 changed files with 1,106 additions and 302 deletions.
8 changes: 4 additions & 4 deletions docs/resources/rdb_acl.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
page_title: "Scaleway: scaleway_rdb_acl"
description: |-
Manages Scaleway Database Instances.
Manages Scaleway Database ACL rules.
---

# scaleway_rdb_acl

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

## Examples

Expand Down Expand Up @@ -36,7 +36,7 @@ The following arguments are supported:
The `acl_rules` block supports:

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


## Attributes Reference
Expand Down
4 changes: 2 additions & 2 deletions docs/resources/rdb_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ The following arguments are supported:
In addition to all arguments above, the following attributes are exported:

- `id` - The ID of the Database Instance.
- `endpoint_ip` - The IP of the Database Instance.
- `endpoint_port` - The port of the Database Instance.
- `endpoint_ip` - (Deprecated) The IP of the Database Instance.
- `endpoint_port` - (Deprecated) The port of the Database Instance.
- `read_replicas` - List of read replicas of the database instance.
- `ip` - IP of the replica.
- `port` - Port of the replica.
Expand Down
4 changes: 3 additions & 1 deletion scaleway/resource_instance_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ func resourceScalewayInstanceIPRead(ctx context.Context, d *schema.ResourceData,
_ = d.Set("organization_id", res.IP.Organization)
_ = d.Set("project_id", res.IP.Project)
_ = d.Set("reverse", res.IP.Reverse)
_ = d.Set("tags", res.IP.Tags)
if len(res.IP.Tags) > 0 {
_ = d.Set("tags", flattenSliceString(res.IP.Tags))
}

if res.IP.Server != nil {
_ = d.Set("server_id", newZonedIDString(res.IP.Zone, res.IP.Server.ID))
Expand Down
1 change: 1 addition & 0 deletions scaleway/resource_rdb_acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func resourceScalewayRdbACL() *schema.Resource {
"description": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Description of the rule",
},
},
Expand Down
32 changes: 32 additions & 0 deletions scaleway/resource_rdb_acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,38 @@ func TestAccScalewayRdbACL_Basic(t *testing.T) {
ProviderFactories: tt.ProviderFactories,
CheckDestroy: testAccCheckScalewayRdbInstanceDestroy(tt),
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(`
resource "scaleway_instance_ip" "front1_ip" {
}
resource "scaleway_instance_ip" "front2_ip" {
}
resource scaleway_rdb_instance main {
name = "%s"
node_type = "db-dev-s"
engine = "PostgreSQL-12"
is_ha_cluster = false
}
resource "scaleway_rdb_acl" "main" {
instance_id = scaleway_rdb_instance.main.id
acl_rules {
ip = "${scaleway_instance_ip.front1_ip.address}/32"
}
acl_rules {
ip = "${scaleway_instance_ip.front2_ip.address}/32"
}
}
`, instanceName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("scaleway_rdb_acl.main", "acl_rules.0.description"),
resource.TestCheckResourceAttrSet("scaleway_rdb_acl.main", "acl_rules.1.description"),
),
},
{
Config: fmt.Sprintf(`
resource scaleway_rdb_instance main {
Expand Down
13 changes: 10 additions & 3 deletions scaleway/resource_rdb_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ func resourceScalewayRdbInstance() *schema.Resource {
Type: schema.TypeString,
Computed: true,
Description: "Endpoint IP of the database instance",
Deprecated: "Please use the private_network or the load_balancer attribute",
},
"endpoint_port": {
Type: schema.TypeInt,
Expand Down Expand Up @@ -280,10 +281,14 @@ func resourceScalewayRdbInstanceCreate(ctx context.Context, d *schema.ResourceDa
DisableBackup: d.Get("disable_backup").(bool),
UserName: d.Get("user_name").(string),
Password: d.Get("password").(string),
Tags: expandStrings(d.Get("tags")),
VolumeType: rdb.VolumeType(d.Get("volume_type").(string)),
}

rawTag, tagExist := d.GetOk("tags")
if tagExist {
createReq.Tags = expandStrings(rawTag)
}

pn, pnExist := d.GetOk("private_network")
if pnExist {
createReq.InitEndpoints, err = expandPrivateNetwork(pn, pnExist)
Expand Down Expand Up @@ -374,7 +379,9 @@ func resourceScalewayRdbInstanceRead(ctx context.Context, d *schema.ResourceData
_ = d.Set("backup_schedule_retention", int(res.BackupSchedule.Retention))
_ = d.Set("user_name", d.Get("user_name").(string)) // user name and
_ = d.Set("password", d.Get("password").(string)) // password are immutable
_ = d.Set("tags", res.Tags)
if len(res.Tags) > 0 {
_ = d.Set("tags", flattenSliceString(res.Tags))
}
if res.Endpoint != nil {
_ = d.Set("endpoint_ip", flattenIPPtr(res.Endpoint.IP))
_ = d.Set("endpoint_port", int(res.Endpoint.Port))
Expand Down Expand Up @@ -442,7 +449,7 @@ func resourceScalewayRdbInstanceUpdate(ctx context.Context, d *schema.ResourceDa
if d.HasChange("backup_schedule_retention") {
req.BackupScheduleRetention = scw.Uint32Ptr(uint32(d.Get("backup_schedule_retention").(int)))
}
if d.HasChange("tags") {
if d.HasChangeExcept("tags") {
req.Tags = scw.StringsPtr(expandStrings(d.Get("tags")))
}

Expand Down

0 comments on commit 7ab8ce0

Please sign in to comment.