Skip to content

Commit

Permalink
feat: keycloak schema
Browse files Browse the repository at this point in the history
  • Loading branch information
dadiorchen committed Oct 31, 2023
1 parent 3b45c5f commit b84f56a
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
7 changes: 7 additions & 0 deletions database-grants/terraform/dev/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,10 @@ module "contracts_schema" {
postgresql = postgresql.treetracker
}
}

module "keycloak_schema" {
source = "./schemas/keycloak"
providers = {
postgresql = postgresql.treetracker
}
}
1 change: 1 addition & 0 deletions database-grants/terraform/dev/schemas/keycloak
44 changes: 44 additions & 0 deletions database-grants/terraform/prod/schemas/keycloak/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
resource "postgresql_schema" "keycloak_schema" {
name = "keycloak"
owner = "doadmin"

}

resource "random_password" "s_password" {
length = 16
special = true
override_special = "_%@"
}

resource "postgresql_role" "service_user" {
name = "s_keycloak"
login = true
password = random_password.s_password.result
search_path = ["keycloak", "public"]
}


resource "postgresql_grant" "service-user-usage" {
database = "treetracker"
role = "s_keycloak"
schema = "keycloak"
object_type = "schema"
privileges = ["USAGE", "CREATE"]
}

resource "postgresql_grant" "table-service-user" {
database = "treetracker"
role = "s_keycloak"
schema = "keycloak"
object_type = "table"
privileges = ["SELECT", "INSERT", "UPDATE", "DELETE"]
}

resource "postgresql_grant" "sequence-service-user" {
database = "treetracker"
role = "s_keycloak"
schema = "keycloak"
object_type = "sequence"
privileges = ["USAGE", "SELECT"]

}
8 changes: 8 additions & 0 deletions database-grants/terraform/prod/schemas/keycloak/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
postgresql = {
source = "cyrilgdn/postgresql"
version = "1.11.0"
}
}
}

0 comments on commit b84f56a

Please sign in to comment.