Hello everyone,
I have a question regarding the PostgreSQL Flexible server resource:
When I create a server via the Azure portal and choose a Private DNS zone, it automatically creates an A record with the private IP of the Postgres server. How can I achieve the same behaviour with Terraform?
I tried the code below but it didn’t work, the Private DNS is created and linked to the VNet, but I can’t find a way to register the A record automatically.
resource "azurerm_postgresql_flexible_server" "db_server" {
name = "${var.environment}-${var.api_app_name}"
resource_group_name = azurerm_resource_group.app.name
location = azurerm_resource_group.app.location
version = "11"
delegated_subnet_id = azurerm_subnet.app.id
administrator_login = "dbadmin"
administrator_password = random_password.dbadmin.result
storage_mb = 32768
sku_name = var.postgres_server_sku
}
resource "azurerm_virtual_network" "app" {
name = var.app_name
address_space = ["10.10.10.0/24"]
location = azurerm_resource_group.app.location
resource_group_name = azurerm_resource_group.app.name
}
resource "azurerm_subnet" "app" {
name = azurerm_resource_group.app.name
resource_group_name = azurerm_resource_group.app.name
virtual_network_name = azurerm_virtual_network.app.name
address_prefixes = ["10.10.10.0/24"]
service_endpoints = ["Microsoft.Storage"]
delegation {
name = "fs"
service_delegation {
name = "Microsoft.DBforPostgreSQL/flexibleServers"
actions = [
"Microsoft.Network/virtualNetworks/subnets/join/action",
]
}
}
}
resource "azurerm_private_dns_zone" "db_server" {
name = "${azurerm_postgresql_flexible_server.db_server.name}.postgres.database.azure.com"
resource_group_name = azurerm_resource_group.app.name
}
resource "azurerm_private_dns_zone_virtual_network_link" "db_server" {
name = "postgres"
resource_group_name = azurerm_resource_group.app.name
private_dns_zone_name = azurerm_private_dns_zone.db_server.name
virtual_network_id = azurerm_virtual_network.app.id
}