Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rdb-acl): tags, ACL description attribute and documentation #1180

Merged
merged 6 commits into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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`
Monitob marked this conversation as resolved.
Show resolved Hide resolved


## 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") {
Monitob marked this conversation as resolved.
Show resolved Hide resolved
req.Tags = scw.StringsPtr(expandStrings(d.Get("tags")))
}

Expand Down