Skip to content

Commit

Permalink
Option to freely define users/roles
Browse files Browse the repository at this point in the history
  • Loading branch information
YannickEvers committed Jul 9, 2024
1 parent 58ef1bf commit b8c09c4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
14 changes: 9 additions & 5 deletions modules/ionos-mongodb-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
}
}
16 changes: 4 additions & 12 deletions modules/ionos-mongodb-cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down

0 comments on commit b8c09c4

Please sign in to comment.