infrastructure/postgresql.tf

24 lines
614 B
Terraform
Raw Normal View History

2024-09-27 23:59:53 +00:00
locals {
service_databases = {for key, val in var.services : key => val if val.database}
}
resource "random_password" "postgresql_service_passwords" {
for_each = local.service_databases
length = 32
special = false
}
resource "postgresql_role" "service_roles" {
for_each = local.service_databases
name = each.value.name
login = true
password = random_password.postgresql_service_passwords[each.key].result
}
resource "postgresql_database" "service_databases" {
for_each = local.service_databases
name = each.value.name
owner = postgresql_role.service_roles[each.key].name
}