File tree Expand file tree Collapse file tree 7 files changed +101
-8
lines changed Expand file tree Collapse file tree 7 files changed +101
-8
lines changed Original file line number Diff line number Diff line change 5
5
Terraform module to create Databases using Scaleway's [ Managed Databases] [ scw-db ] .
6
6
7
7
Create and configure the following:
8
- - Database Instance
8
+ - Managed RDB Instances
9
9
- Database Users
10
10
- Database ACLs
11
+ - Managed Databases
11
12
12
13
[ scw-db ] : https://www.scaleway.com/en/database/
13
14
@@ -41,6 +42,7 @@ Multiple examples are available in the [`./examples`](./examples) directory.
41
42
- A [ simple database setup] ( ./examples/simple/ )
42
43
- [ Multiple database creation with users] ( ./examples/users/ )
43
44
- [ Database creation with ACL support] ( ./examples/acls/ )
45
+ - [ RDB instance with multiple databases] ( ./examples/databases/ )
44
46
45
47
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
46
48
## Requirements
Original file line number Diff line number Diff line change
1
+ resource "scaleway_rdb_database" "this" {
2
+ for_each = local. dbs_by_database
3
+
4
+ instance_id = scaleway_rdb_instance. this [each . value . database ]. id
5
+ name = each. value . db
6
+ }
7
+
Original file line number Diff line number Diff line change
1
+ # Databases Example
2
+
3
+ Managed Database creation with database support.
4
+
5
+ ``` hcl
6
+ module "rdb" {
7
+ source = "../../"
8
+
9
+ databases = {
10
+ main = {
11
+ name = "database-with-multiple-dbs"
12
+ node_type = "DB-DEV-S"
13
+ engine = "PostgreSQL-11"
14
+ dbs = [
15
+ "default",
16
+ "admin",
17
+ "internal",
18
+ ]
19
+ }
20
+ }
21
+ }
22
+ ```
23
+
24
+ <!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
25
+ ## Requirements
26
+
27
+ No requirements.
28
+
29
+ ## Providers
30
+
31
+ No providers.
32
+
33
+ ## Modules
34
+
35
+ | Name | Source | Version |
36
+ | ------| --------| ---------|
37
+ | <a name =" module_rdb " ></a > [ rdb] ( #module\_ rdb ) | ../../ | n/a |
38
+
39
+ ## Resources
40
+
41
+ No resources.
42
+
43
+ ## Inputs
44
+
45
+ No inputs.
46
+
47
+ ## Outputs
48
+
49
+ | Name | Description |
50
+ | ------| -------------|
51
+ | <a name =" output_rdb " ></a > [ rdb] ( #output\_ rdb ) | n/a |
52
+ <!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Original file line number Diff line number Diff line change
1
+ module "rdb" {
2
+ source = " ../../"
3
+
4
+ databases = {
5
+ main = {
6
+ name = " database-with-multiple-dbs"
7
+ node_type = " DB-DEV-S"
8
+ engine = " PostgreSQL-11"
9
+ dbs = [
10
+ " default" ,
11
+ " admin" ,
12
+ " internal" ,
13
+ ]
14
+ }
15
+ }
16
+ }
17
+
18
+ output "rdb" {
19
+ value = module. rdb . this
20
+ sensitive = true
21
+ }
Original file line number Diff line number Diff line change @@ -7,6 +7,14 @@ locals {
7
7
}
8
8
]
9
9
])
10
+ db_configs = flatten ([
11
+ for database , config in local . databases : [
12
+ for db in config . dbs : {
13
+ database = database
14
+ db = db
15
+ }
16
+ ]
17
+ ])
10
18
acl_configs = flatten ([
11
19
for database , config in local . databases : [
12
20
for acl in config . acls : {
@@ -23,12 +31,17 @@ locals {
23
31
for config in local . user_configs :
24
32
" ${config.database}_${config.user.username}" => config
25
33
}
34
+ dbs_by_database = {
35
+ for config in local . db_configs :
36
+ " ${config.database}_${config.db}" => config
37
+ }
26
38
default_database = {
27
39
name = " default"
28
40
node_type = " DB-DEV-S"
29
41
users = []
30
42
settings = {}
31
43
acls = []
44
+ dbs = []
32
45
}
33
46
databases = {
34
47
for database_name , config in var . databases :
Original file line number Diff line number Diff line change 1
- resource "scaleway_rdb_database" "this" {
2
- for_each = local. databases
3
- instance_id = scaleway_rdb_instance. this [each . key ]. id
4
- name = each. key
5
- }
6
-
7
1
resource "scaleway_rdb_instance" "this" {
8
2
for_each = local. databases
9
3
Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ output "this" {
2
2
value = {
3
3
for name in keys (var. databases ) : name => {
4
4
" instance" = scaleway_rdb_instance.this[name],
5
- " database" = scaleway_rdb_database.this[name],
6
5
" acls" = lookup (scaleway_rdb_acl. this , name, []),
7
6
" users" = [
8
7
for identifier , config in local . user_by_database : {
@@ -12,6 +11,11 @@ output "this" {
12
11
" identifier" : identifier
13
12
} if config. database == name
14
13
],
14
+ " dbs" = [
15
+ for identifier , config in local . dbs_by_database :
16
+ scaleway_rdb_database . this [identifier ]
17
+ if config . database == name
18
+ ]
15
19
}
16
20
}
17
21
description = " A map of the scaleway_rdb_database (including their users) and scaleway_rdb_instance resources grouped by databases definitions"
You can’t perform that action at this time.
0 commit comments