From 9c8bc57e48e421fe5a234b53d5954c988842e896 Mon Sep 17 00:00:00 2001 From: michaeljguarino Date: Fri, 5 Jan 2024 18:35:23 -0500 Subject: [PATCH] define postgres database --- terraform/clouds/azure/locals.tf | 2 +- terraform/clouds/azure/postgres.tf | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/terraform/clouds/azure/locals.tf b/terraform/clouds/azure/locals.tf index 371c1e1..3b27c4d 100644 --- a/terraform/clouds/azure/locals.tf +++ b/terraform/clouds/azure/locals.tf @@ -5,5 +5,5 @@ locals { name = var.create_resource_group ? azurerm_resource_group.main[0].name : var.resource_group_name location = var.location } - db_url = format("postgresql://console:%s@%s:5432/console", random_password.password.result, try(azurerm_postgresql_flexible_server.postgres.fqdn, "")) + db_url = format("postgresql://console:%s@%s:5432/console", random_password.password.result, try(azurerm_postgresql_flexible_server.postgres[0].fqdn, "")) } \ No newline at end of file diff --git a/terraform/clouds/azure/postgres.tf b/terraform/clouds/azure/postgres.tf index ba01b86..455aaae 100644 --- a/terraform/clouds/azure/postgres.tf +++ b/terraform/clouds/azure/postgres.tf @@ -7,18 +7,21 @@ resource "random_password" "password" { } resource "azurerm_private_dns_zone" "postgres" { - name = "postgres.database.azure.com" + count = var.create_db ? 1 : 0 + name = "plrl.database.azure.com" resource_group_name = local.resource_group.name } resource "azurerm_private_dns_zone_virtual_network_link" "postgres" { - name = "plural.postgres.com" + count = var.create_db ? 1 : 0 + name = "plrl.postgres.com" private_dns_zone_name = azurerm_private_dns_zone.postgres.name virtual_network_id = azurerm_virtual_network.network.id resource_group_name = local.resource_group.name } resource "azurerm_postgresql_flexible_server" "postgres" { + count = var.create_db ? 1 : 0 name = var.db_name resource_group_name = local.resource_group.name location = local.resource_group.location @@ -31,4 +34,12 @@ resource "azurerm_postgresql_flexible_server" "postgres" { storage_mb = var.postgres_disk sku_name = var.postgres_sku +} + +resource "azurerm_postgresql_flexible_server_database" "example" { + count = var.create_db ? 1 : 0 + name = "console" + server_id = azurerm_postgresql_flexible_server.postgres[0].id + collation = "en_US.utf8" + charset = "utf8" } \ No newline at end of file