Skip to content

Commit

Permalink
define postgres database
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljguarino committed Jan 5, 2024
1 parent 05c0179 commit 9c8bc57
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion terraform/clouds/azure/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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, ""))
}
15 changes: 13 additions & 2 deletions terraform/clouds/azure/postgres.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
}

0 comments on commit 9c8bc57

Please sign in to comment.