From 895cfc6a4390da69e8867669171eb4be695e6d2a Mon Sep 17 00:00:00 2001 From: pgvishnuram <81585115+pgvishnuram@users.noreply.github.com> Date: Fri, 2 Aug 2024 17:36:58 +0530 Subject: [PATCH] add db engine based conn string (#78) * add db engine based conn string * fix db engine prefix --- terraform/outputs.tf | 2 +- terraform/variables.tf | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/terraform/outputs.tf b/terraform/outputs.tf index d5f76bd..454e0e5 100644 --- a/terraform/outputs.tf +++ b/terraform/outputs.tf @@ -19,7 +19,7 @@ output "bastion_proxy_command" { } output "db_connection_string" { - value = var.deploy_db ? "postgres://${element(concat(tolist(google_sql_user.airflow.*.name)), 0)}:${local.postgres_airflow_password}@${element(concat(tolist(google_sql_database_instance.instance.*.private_ip_address)), 0)}:5432" : "N/A: DB is not deployed with the terraform-google-astronomer-gcp module. Set deploy_db = true" + value = var.deploy_db ? "${local.db_engine == "mysql" ? "mysql://" : "postgres://"}${element(concat(tolist(google_sql_user.airflow.*.name)), 0)}:${local.postgres_airflow_password}@${element(concat(tolist(google_sql_database_instance.instance.*.private_ip_address)), 0)}:${var.database_ports[local.db_engine].port}" : "N/A: DB is not deployed with the terraform-google-astronomer-gcp module. Set deploy_db = true" sensitive = true } diff --git a/terraform/variables.tf b/terraform/variables.tf index faf9db6..ab67c46 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -136,6 +136,19 @@ variable "db_version" { description = "define postgres database version" } +variable "database_ports" { + type = map(any) + default = { + "mysql" = { + port = 3306 + } + "postgres" = { + port = 5432 + } + } + description = "Optional configuration to define postgres db version" +} + variable "db_deletion_protection" { type = bool default = true