From bedae897caf50c27cbf8fd8569b242dbf1ec4a78 Mon Sep 17 00:00:00 2001 From: Noah Spannbauer Date: Mon, 27 Jan 2025 17:26:43 -0600 Subject: [PATCH] First commit --- .gitignore | 1 + README.md | 0 config.tf | 0 helm_values/postgresql.yaml | 22 ++++++++++++++++++++++ main.tf | 0 postgres.tf | 15 +++++++++++++++ providers.tf | 16 ++++++++++++++++ terraform.tf | 15 +++++++++++++++ variables.tf | 15 +++++++++++++++ 9 files changed, 84 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 config.tf create mode 100644 helm_values/postgresql.yaml create mode 100644 main.tf create mode 100644 postgres.tf create mode 100644 providers.tf create mode 100644 terraform.tf create mode 100644 variables.tf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..88ba98a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +**/*.auto.tfvars \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/config.tf b/config.tf new file mode 100644 index 0000000..e69de29 diff --git a/helm_values/postgresql.yaml b/helm_values/postgresql.yaml new file mode 100644 index 0000000..65aeee3 --- /dev/null +++ b/helm_values/postgresql.yaml @@ -0,0 +1,22 @@ +global: + defaultStorageClass: standard + postgresql: + auth: + username: ${postgres_user} + password: ${postgres_password} +primary: + extraEnvVars: + - name: VELA_USER + value: ${vela_user} + - name: VELA_PASSWORD + value: ${vela_password} + initdb: + scripts: + user: ${postgres_user} + password: ${postgres_password} + db_init_script.sh: | + PGPASSWORD=$${POSTGRES_PASSWORD} psql -U $${POSTGRES_USER} <<-END + CREATE USER $${VELA_USER} WITH PASSWORD '$${VELA_PASSWORD}'; + SELECT 'CREATE DATABASE vela WITH OWNER $${VELA_USER}' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'vela')\gexec + GRANT ALL PRIVILEGES ON DATABASE vela TO $${VELA_USER}; + END \ No newline at end of file diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..e69de29 diff --git a/postgres.tf b/postgres.tf new file mode 100644 index 0000000..07fbf52 --- /dev/null +++ b/postgres.tf @@ -0,0 +1,15 @@ +resource "helm_release" "postgresql" { + name = "postgresql" + repository = "https://charts.bitnami.com/bitnami" + chart = "postgresql" + namespace = "default" + create_namespace = false + version = "15.5.23" + + values = [templatefile("${path.module}/helm_values/postgresql.yaml", { + postgres_user = "${var.POSTGRES_USER}" + postgres_password = "${var.POSTGRES_PASSWORD}" + vela_user = "${var.VELA_USER}" + vela_password = "${var.VELA_PASSWORD}" + })] +} \ No newline at end of file diff --git a/providers.tf b/providers.tf new file mode 100644 index 0000000..fdc4f2c --- /dev/null +++ b/providers.tf @@ -0,0 +1,16 @@ +provider "helm" { + kubernetes { + config_path = "~/.kube/config" + config_context = "minikube" + } +} + +provider "kubectl" { + config_path = "~/.kube/conifg" + config_context = "minikube" +} + +provider kubernetes { + config_path = "~/.kube/config" + config_context = "minikube" +} \ No newline at end of file diff --git a/terraform.tf b/terraform.tf new file mode 100644 index 0000000..8e23e0c --- /dev/null +++ b/terraform.tf @@ -0,0 +1,15 @@ +terraform { + required_providers { + helm = { + source = "hashicorp/helm" + } + + kubectl = { + source = "gavinbunney/kubectl" + } + + kubernetes = { + source = "hashicorp/kubernetes" + } + } +} \ No newline at end of file diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..5d02c12 --- /dev/null +++ b/variables.tf @@ -0,0 +1,15 @@ +variable "POSTGRES_USER" { + type = string +} + +variable "POSTGRES_PASSWORD" { + type = string +} + +variable "VELA_USER" { + type = string +} + +variable "VELA_PASSWORD" { + type = string +} \ No newline at end of file