-
Notifications
You must be signed in to change notification settings - Fork 1
/
database_users.tf
37 lines (35 loc) · 1.14 KB
/
database_users.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
########################################
### RANDOM PASSWORD FOR DATABASE USERS
######################### ##############
resource "random_password" "password" {
for_each = var.create ? local.db_users_flat : {}
length = 16
special = true
override_special = "_%!+"
}
resource "mongodbatlas_database_user" "user" {
for_each = var.create ? local.db_users_flat : {}
username = each.value.username
password = random_password.password[each.key].result
project_id = mongodbatlas_project.project[0].id
auth_database_name = "admin"
dynamic "roles" {
for_each = range(length(each.value.cluster.db_name))
content {
database_name = each.value.cluster.db_name[roles.key]
role_name = each.value.cluster.db_role[roles.key]
}
}
dynamic "scopes" {
for_each = range(length(each.value.cluster.clustername))
content {
name = each.value.cluster.clustername[scopes.key]
type = each.value.cluster.db_type[scopes.key]
}
}
depends_on = [
mongodbatlas_project.project,
#mongodbatlas_cluster.cluster,
random_password.password
]
}