diff --git a/modules/ionos-mongodb-cluster/main.tf b/modules/ionos-mongodb-cluster/main.tf index b4d65f1..7c6e674 100644 --- a/modules/ionos-mongodb-cluster/main.tf +++ b/modules/ionos-mongodb-cluster/main.tf @@ -26,11 +26,15 @@ resource ionoscloud_mongo_cluster "mongo_cluster" { } resource "ionoscloud_mongo_user" "initial_mongo_user" { + for_each = var.users cluster_id = ionoscloud_mongo_cluster.mongo_cluster.id - username = var.username - password = var.password - roles { - role = var.role - database = "admin" + username = each.key + password = each.value.password + dynamic "roles" { + for_each = each.value.roles + content { + role = roles.value["role"] + database = roles.value["db"] + } } } diff --git a/modules/ionos-mongodb-cluster/variables.tf b/modules/ionos-mongodb-cluster/variables.tf index 1c555ba..acc4501 100644 --- a/modules/ionos-mongodb-cluster/variables.tf +++ b/modules/ionos-mongodb-cluster/variables.tf @@ -73,18 +73,10 @@ variable "ip_block_start" { type = number default = 101 } -variable "username" { - description = "The username for the initial mongo user" - type = string -} -variable "password" { - description = "The password for the initial mongo user" - type = string -} -variable "role" { - description = "The role of the initial mongo user (Default: dbAdminAnyDatabase)" - type = string - default = "dbAdminAnyDatabase" +variable "users" { + description = "Map of users and their roles. Example: {admin: {password: \"1234\", roles: [{db: \"admin\", role: \"dbAdminAnyDatabase\"}]}}" + default = {} + type = map(object({password=string, roles=set(object({db=string, role=string}))})) } variable "maintenance_day" { description = "The day of the week for the 4 hour-long maintenance window (Default: Sunday)"