Azurerm_postgresql_flexible_server is failing with "polling after Create: context deadline exceeded" error after 60 mins

Hi there…

Here are my configuration files for deploying a Postgres flexible server in Azure:

module "naming" {
  source  = "Azure/naming/azurerm"
  version = "~> 0.3"
}


resource "azurerm_resource_group" "my_resource_group" {
  location = var.location
  name     = var.my_resource_group_name
}

resource "random_password" "myadminpassword" {
  length           = 16
  override_special = "_%@"
  special          = true
}


module "postgres-server" {
  depends_on = [azurerm_resource_group.my_resource_group]
  source     = "Azure/avm-res-dbforpostgresql-flexibleserver/azurerm"
  # version    = "0.1.0"

  location            = var.location
  name                = var.my_server_name
  resource_group_name = azurerm_resource_group.my_resource_group.name
  # enable_telemetry       = var.enable_telemetry
  administrator_login    = azurerm_key_vault_secret.admin_login.value
  administrator_password = random_password.myadminpassword.result
  storage_mb             = var.storage_mb
  storage_tier           = var.storage_tier
  backup_retention_days  = var.backup_retention_days
  server_version         = 16
  sku_name               = "GP_Standard_D2s_v3"
  zone                   = 1
  high_availability = {
    mode                      = "ZoneRedundant"
    standby_availability_zone = 2
  }
  tags = null
}

And somehow its failing after trying for 60 mins with a weird context deadline exceeded error as shown below:

module.postgres-server.module.postgres-server.azurerm_postgresql_flexible_server.this: Still creating... [59m30s elapsed]
module.postgres-server.module.postgres-server.azurerm_postgresql_flexible_server.this: Still creating... [59m40s elapsed]
module.postgres-server.module.postgres-server.azurerm_postgresql_flexible_server.this: Still creating... [59m50s elapsed]
╷
│ Error: creating Flexible Server (Subscription: "***"
│ Resource Group Name: "my-resource-group"
│ Flexible Server Name: "my-postgres-server"): polling after Create: context deadline exceeded
│ 
│   with module.postgres-server.module.postgres-server.azurerm_postgresql_flexible_server.this,
│   on .terraform/modules/postgres-server.postgres-server/main.tf line 1, in resource "azurerm_postgresql_flexible_server" "this":
│    1: resource "azurerm_postgresql_flexible_server" "this" {
│ 
╵
Error: Terraform exited with code 1.
Error: Process completed with exit code 1.

And when I re-run it, it complains that the resource azurerm_postgresql_flexible_server exists and I need to import it into my state file:

module.postgres-server.module.postgres-server.azurerm_postgresql_flexible_server.this: Creating...
╷
│ Error: A resource with the ID "/subscriptions/***/resourceGroups/my-postgres-resource-group/providers/Microsoft.DBforPostgreSQL/flexibleServers/my-postgres-server" already exists - to be managed via Terraform this resource needs to be imported into the State. Please see the resource documentation for "azurerm_postgresql_flexible_server" for more information.
│ 
│   with module.postgres-server.module.postgres-server.azurerm_postgresql_flexible_server.this,
│   on .terraform/modules/postgres-server.postgres-server/main.tf line 1, in resource "azurerm_postgresql_flexible_server" "this":
│    1: resource "azurerm_postgresql_flexible_server" "this" {
│ 
╵
Error: Terraform exited with code 1.

What am I missing here with this configuration? Any help is appreciated people :slight_smile:

The server name for Azure Database for PostgreSQL flexible server must be unique.

If someone somewhere around the world is already using that name, you won’t be able to create the PostgreSQL.

Change to name to something unique.

1 Like

Testing. I will update in a bit.

Wondering why it’s taking 60 mins until it errors out? I ran the pipeline and it’s going on right now. Waiting for it to finish.