Skip to content

Commit

Permalink
Merge pull request #5 from particuleio/feat/add-rdb-acl-support
Browse files Browse the repository at this point in the history
feat: add RDB ACL support
  • Loading branch information
tbobm authored Oct 22, 2021
2 parents 11ab8de + 708d937 commit ab1de2f
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ No modules.
| Name | Type |
|------|------|
| [random_password.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource |
| [scaleway_rdb_acl.this](https://registry.terraform.io/providers/scaleway/scaleway/latest/docs/resources/rdb_acl) | resource |
| [scaleway_rdb_database.this](https://registry.terraform.io/providers/scaleway/scaleway/latest/docs/resources/rdb_database) | resource |
| [scaleway_rdb_instance.this](https://registry.terraform.io/providers/scaleway/scaleway/latest/docs/resources/rdb_instance) | resource |
| [scaleway_rdb_user.this](https://registry.terraform.io/providers/scaleway/scaleway/latest/docs/resources/rdb_user) | resource |
Expand Down
14 changes: 14 additions & 0 deletions acls.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
resource "scaleway_rdb_acl" "this" {
for_each = local.databases

instance_id = scaleway_rdb_instance.this[each.key].id

dynamic "acl_rules" {
for_each = each.value.acls

content {
ip = acl_rules.value["ip"]
description = acl_rules.value["description"]
}
}
}
26 changes: 26 additions & 0 deletions examples/acls/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module "rdb" {
source = "../../"

databases = {
main = {
name = "test-simple-db"
node_type = "DB-DEV-S"
engine = "PostgreSQL-11"
acls = [
{
ip = "1.2.3.4/32"
description = "Specific ACL 1"
},
{
ip = "192.168.1.20/28"
description = "Specific ACL 2"
}
]
}
}
}

output "rdb" {
value = module.rdb.this
sensitive = true
}
16 changes: 12 additions & 4 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@ locals {
}
]
])
acl_configs = flatten([
for database, config in local.databases : [
for acl in config.acls : {
database = database
rule = acl
}
]
])
acls_by_database = {
for index, config in local.acl_configs :
"${config.database}_${index}" => config
}
user_by_database = {
for config in local.user_configs :
"${config.database}_${config.user.username}" => config
}
user_computed = {
for identifier, config in local.user_by_database :
config.database => config...
}
default_database = {
name = "default"
node_type = "DB-DEV-S"
Expand Down
1 change: 1 addition & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ output "this" {
for name in keys(var.databases) : name => {
"instance" = scaleway_rdb_instance.this[name],
"database" = scaleway_rdb_database.this[name],
"acls" = scaleway_rdb_acl.this[name],
"users" = [
for identifier, config in local.user_by_database : {
"username" : config.user.username,
Expand Down

0 comments on commit ab1de2f

Please sign in to comment.