This commit is contained in:
Ariel Sosnovsky committed 2023-11-10 17:31:49 -05:00
1 parent f9c5f72b46
commit 3159491473
4 files changed
+30 -2

No files matched your search

@@ -5,5 +5,8 @@ cp -r /app /tmp/app
cd /tmp/app && \
terraform init && \
terraform apply -auto-approve -input=false -var-file="/app/users.tfvars" -lock=false
terraform apply -auto-approve -input=false \
-var-file="/app/users.tfvars" \
-var-file="/app/db_users_dbs.tfvars" \
-lock=false
{{- end -}}
@@ -5,11 +5,15 @@ variable "db_password" {}
variable "db_users" {
type = list(string)
}
variable "db_users_dbs" {
type = map(list(string))
default = {}
}
terraform {
required_providers {
postgresql = {
source = "cyrilgdn/postgresql"
version = "1.18.0"
version = "{{.Values.terraform.cyrilgdnPostgresql.tag}}"
}
}
}
@@ -46,6 +50,11 @@ locals {
for u, pwd in random_password.pg_users_pswd :
var.db_users[u] => pwd.result
}
users_db = flatten([
for user, dbs in var.db_users_dbs:
for db in dbs:
{"db": db, "user": user}
])
}
resource "kubernetes_secret" "pg_users" {
@@ -79,5 +88,11 @@ resource "postgresql_database" "db" {
owner = postgresql_role.u[each.key].id
}
resource "postgresql_database" "db_users" {
for_each = local.users_db
name = each.value.db
owner = postgresql_role.u[each.value.user].id
}
{{- end -}}
@@ -9,3 +9,4 @@ data:
run.sh: "{{ include "pg-users.entry" . | b64enc }}"
main.tf: "{{ include "pg-users.terraform" . | b64enc }}"
users.tfvars: "{{ (print "db_users = " ( .Values.userGeneration.users | toJson )) | b64enc }}"
db_users_dbs.tfvars: "{{ (print "db_users_dbs = " ( .Values.userGeneration.users_dbs | toJson )) | b64enc }}"
+9
View File
@@ -3,5 +3,14 @@ userGeneration:
users:
- nextcloud
- authentik
- radarr
- sonarr
users_dbs:
radarr: [radarr-main, radarr-log]
sonarr: [sonarr-main, sonarr-log]
postgresSecret: ""
terraform:
cyrilgdnPostgresql:
tag: 1.18.0