-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
46 lines (39 loc) · 1.09 KB
/
main.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
38
39
40
41
42
43
44
45
46
terraform {
required_providers {
mongodbatlas = {
source = "mongodb/mongodbatlas"
}
}
}
provider "mongodbatlas" {
public_key = "<YOUR PUBLIC KEY HERE>"
private_key = "<YOUR PRIVATE KEY HERE>"
}
data "mongodbatlas_cluster" "db" {
project_id = var.mongodbatlas_project_id
name = var.cluster_name
}
resource "random_password" "store-service-password" {
# Generate a unique new password for the DB user
#count = 3
length = 10
special = true
min_upper = 1
min_lower = 1
min_numeric = 1
}
resource "mongodbatlas_database_user" "dbuser"{
for_each = {for val in var.service_configuration: val.serviceName => val}
username = "${each.value.serviceName}"
password = random_password.store-srevice-password
project_id = var.mongodbatlas_project_id
auth_auth_databse_name = "admin"
dynamic roles{
for_each = each.value.mongoCollection[*]
content {
role_name = "read"
database_name = each.value.mongoDatabase
collection_name = roles.value
}
}
}