Unable to create Azure Database for Postgres Flexible Server using terraform script due to Internal Server Error.
Hello everyone, I'm unable to create an azurerm_postgresql_flexible_server resource using terrafrom script. I'm getting following error:
user@host:~/infra$ terraform apply tfplan.terraform
azurerm_postgresql_flexible_server.postgressrv: Creating...
azurerm_postgresql_flexible_server.postgressrv: Still creating... [10s elapsed]
azurerm_postgresql_flexible_server.postgressrv: Still creating... [20s elapsed]
azurerm_postgresql_flexible_server.postgressrv: Still creating... [30s elapsed]
azurerm_postgresql_flexible_server.postgressrv: Still creating... [40s elapsed]
azurerm_postgresql_flexible_server.postgressrv: Still creating... [50s elapsed]
azurerm_postgresql_flexible_server.postgressrv: Still creating... [1m0s elapsed]
╷
│ Error: creating Flexible Server (Subscription: "<mysubid>"
│ Resource Group Name: "resgroup-test-postgressrv"
│ Flexible Server Name: "postgres-common-test"): polling after Create: polling failed: the Azure API returned the following error:
│
│ Status: "InternalServerError"
│ Code: ""
│ Message: "An unexpected error occured while processing the request. Tracking ID: '<some_tracking_id>'"
│ Activity Id: ""
│
│ ---
│
│ API Response:
│
│ ----[start]----
│ {"name":"<some_activity_id>","status":"Failed","startTime":"2025-03-07T08:42:00.087Z","error":{"code":"InternalServerError","message":"An unexpected error occured while processing the request. Tracking ID: '<some_tracking_id>'"}}
│ -----[end]-----
│
│
│ with azurerm_postgresql_flexible_server.postgressrv,
│ on main.tf line 6, in resource "azurerm_postgresql_flexible_server" "postgressrv":
│ 6: resource "azurerm_postgresql_flexible_server" "postgressrv" {
Here's my script:
main.tf
resource "azurerm_resource_group" "resource_group" {
name = local.resource_group_name
location = var.location
}
resource "azurerm_postgresql_flexible_server" "postgressrv" {
name = local.hostname
resource_group_name = azurerm_resource_group.resource_group.name
location = azurerm_resource_group.resource_group.location
version = var.pg_version
administrator_login = var.username
administrator_password = var.password
zone = 3
storage_mb = 32768
storage_tier = "P4"
sku_name = var.sku_name
backup_retention_days = 7
geo_redundant_backup_enabled = false
public_network_access_enabled = true
auto_grow_enabled = true
authentication {
password_auth_enabled = true
}
tags = {
env = var.env
purpose = "airflow"
}
depends_on = [azurerm_resource_group.resource_group]
}
variables.tf
variable "env" {
default = "test"
}
variable "pg_version" {
default = "16"
}
variable "location" {
default = "northeurope"
}
variable "sku_name" {
default = "B_Standard_B1ms"
}
variable "username" {
default = "mytestpgadmin"
}
variable "password" {
default = "H4sh1C0rp!!"
}
providers.tf
terraform {
required_version = ">=1.0"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~>3.0"
}
}
}
provider "azurerm" {
features {}
}
I have already tried removing or changing the zone from 3 to 2 or even 1. I've used Azure Portal to create the same resource, and I was able to create it with same configuration using Azure Portal. What am I doing wrong here, I've prepared this script by following the examples, given at https://registry.terraform.io/providers/tfproviders/azurerm/latest/docs/resources/postgresql_flexible_server
and
https://learn.microsoft.com/en-us/azure/developer/terraform/deploy-postgresql-flexible-server-database?tabs=azure-cli