-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.tf
31 lines (26 loc) · 902 Bytes
/
database.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
resource "google_sql_database" "database" {
count = length(keys(var.databases))
name = "${element(keys(var.databases), count.index)}-${var.environment}"
project = var.google_project
instance = google_sql_database_instance.instance.name
charset = "UTF8"
}
// TODO replace with GCP Secret Manager dynamic credentials in the future, per database for now
resource "random_string" "password" {
count = length(keys(var.databases))
length = 32
number = true
lower = true
upper = true
special = false
}
resource "google_sql_user" "database_user" {
count = length(keys(var.databases))
name = lookup(element(values(var.databases), count.index), "user")
project = var.google_project
instance = google_sql_database_instance.instance.name
password = random_string.password[count.index].result
depends_on = [
google_sql_database_instance.instance,
]
}