postgres-provisionning/generic-database/database.tf

31 lines
748 B
HCL

resource "random_password" "password" {
length = 16
special = true
override_special = "$*()=+[]{}<>?"
}
resource "postgresql_role" "user" {
name = var.username
password = random_password.password.result
login = true
}
resource "postgresql_database" "database" {
name = var.database_name
template = "template0"
encoding = "UTF8"
lc_collate = var.collate
lc_ctype = var.ctype
connection_limit = -1
allow_connections = true
}
resource "postgresql_grant" "readonly_tables" {
database = postgresql_database.database.name
role = postgresql_role.user.name
schema = var.schema
object_type = "database"
privileges = var.privileges
}