Skip to content

Commit ab1de2f

Browse files
authored
Merge pull request #5 from particuleio/feat/add-rdb-acl-support
feat: add RDB ACL support
2 parents 11ab8de + 708d937 commit ab1de2f

File tree

5 files changed

+54
-4
lines changed

5 files changed

+54
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ No modules.
3939
| Name | Type |
4040
|------|------|
4141
| [random_password.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource |
42+
| [scaleway_rdb_acl.this](https://registry.terraform.io/providers/scaleway/scaleway/latest/docs/resources/rdb_acl) | resource |
4243
| [scaleway_rdb_database.this](https://registry.terraform.io/providers/scaleway/scaleway/latest/docs/resources/rdb_database) | resource |
4344
| [scaleway_rdb_instance.this](https://registry.terraform.io/providers/scaleway/scaleway/latest/docs/resources/rdb_instance) | resource |
4445
| [scaleway_rdb_user.this](https://registry.terraform.io/providers/scaleway/scaleway/latest/docs/resources/rdb_user) | resource |

acls.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
resource "scaleway_rdb_acl" "this" {
2+
for_each = local.databases
3+
4+
instance_id = scaleway_rdb_instance.this[each.key].id
5+
6+
dynamic "acl_rules" {
7+
for_each = each.value.acls
8+
9+
content {
10+
ip = acl_rules.value["ip"]
11+
description = acl_rules.value["description"]
12+
}
13+
}
14+
}

examples/acls/main.tf

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module "rdb" {
2+
source = "../../"
3+
4+
databases = {
5+
main = {
6+
name = "test-simple-db"
7+
node_type = "DB-DEV-S"
8+
engine = "PostgreSQL-11"
9+
acls = [
10+
{
11+
ip = "1.2.3.4/32"
12+
description = "Specific ACL 1"
13+
},
14+
{
15+
ip = "192.168.1.20/28"
16+
description = "Specific ACL 2"
17+
}
18+
]
19+
}
20+
}
21+
}
22+
23+
output "rdb" {
24+
value = module.rdb.this
25+
sensitive = true
26+
}

locals.tf

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,22 @@ locals {
77
}
88
]
99
])
10+
acl_configs = flatten([
11+
for database, config in local.databases : [
12+
for acl in config.acls : {
13+
database = database
14+
rule = acl
15+
}
16+
]
17+
])
18+
acls_by_database = {
19+
for index, config in local.acl_configs :
20+
"${config.database}_${index}" => config
21+
}
1022
user_by_database = {
1123
for config in local.user_configs :
1224
"${config.database}_${config.user.username}" => config
1325
}
14-
user_computed = {
15-
for identifier, config in local.user_by_database :
16-
config.database => config...
17-
}
1826
default_database = {
1927
name = "default"
2028
node_type = "DB-DEV-S"

outputs.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ output "this" {
33
for name in keys(var.databases) : name => {
44
"instance" = scaleway_rdb_instance.this[name],
55
"database" = scaleway_rdb_database.this[name],
6+
"acls" = scaleway_rdb_acl.this[name],
67
"users" = [
78
for identifier, config in local.user_by_database : {
89
"username" : config.user.username,

0 commit comments

Comments
 (0)