Postgres Flexible Server - Terraform Deployment stuck

Markus Bauer 20 Reputation points
2024-09-18T12:50:32.8133333+00:00

Hi everybody,

I've run into a very interesting problem: I cannot seem to deploy a Postgres Flexible Server using Terraform.

Using the config below and the azurerm provider in version "4.2.0" Terraform seems to get stuck in the creation process indefinitely (I've been waiting for upwards of an hour with nothing happening). Authentication is done via my own user (using az login). Which has worked for all other services I've deployed so far (DNS zones and entries, vNets, Subnets, AKS clusters etc.)

Terraform Debug Logging does not reveal any errors or really anything that would indicate an issue even when on Trace level. Even funnier is, that, using Azure CLI and az postgres flexible-server list

shows that there is indeed a database server deployed, however it is not visible in the UI, it is not reachable, Terraform, as mentioned above, is not able to complete the apply etc.

Cancelling the apply and then re-running it, however results in an error as the database server apparently already exists. Which then results in me having to manually delete it via Azure CLI.

It is all pretty weird an I'm out of ideas.

Also: the Activity Log shows a ton of "Get PostgreSQL server list" entries that correlate with me running Terraform apply and leaving it running.

Manually setting up a server via the UI works as it should - no issues there.

resource "azurerm_postgresql_flexible_server" "dev-server-01" {
  name                   = "${local.deployment_name}-server"
  location            = data.azurerm_resource_group.ml-north.location
  resource_group_name = data.azurerm_resource_group.ml-north.name
  version                = "16"
  create_mode            = "Default"
  administrator_login    = "adminTerraform"
  administrator_password = random_password.pass.result
  authentication {
    password_auth_enabled = true
  }
  zone                   = "1"
  storage_mb             = 32768
  sku_name               = "B_Standard_B1ms"
  backup_retention_days  = 7
  public_network_access_enabled = true

}

Azure Database for PostgreSQL
0 comments No comments
{count} votes

Accepted answer
  1. ShaktiSingh-MSFT 15,301 Reputation points
    2024-09-19T09:15:11.8966667+00:00

    Hi @Markus Bauer ,

    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to "Accept " the answer.

    Issue:

    Solution taken in cx verbatim:

    It turns out, Azure backend got confused by concurring "Create" and "Drop" operations because I might have messed up somewhere in the beginning. Due to this, the database name I chose was already in use and Azure could not create the flexible Postgres server. Simply changing the name of the server seems to have fixed it.

    If you have any other questions or are still running into more issues, please let me know. Thank you again for your time and patience throughout this issue.

    Please remember to "Accept Answer" if any answer/reply helped, so that others in the community facing similar issues can easily find the solution.

    Thanks

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Vinodh247 20,476 Reputation points
    2024-09-18T13:27:59.38+00:00
    • Ensure You're Using the Correct Version of the AzureRM Provider
    • Since the creation process is hanging indefinitely, you can configure Terraform to timeout after a certain period and fail the process. This might give you more control when debugging long-running operations.
    • You mentioned seeing many "Get PostgreSQL server list" entries. This could be due to Terraform polling for updates too aggressively. Try disabling or reducing logging verbosity by adjusting the environment variables.
    • There might be a resource lock (ex: a CanNotDelete lock) on the resource group or PostgreSQL server that's preventing Terraform from completing the operation.
    • If the deployment fails but still partially creates the PostgreSQL Flexible Server, manually clean up those resources via CLI before attempting to redeploy.

  2. Markus Bauer 20 Reputation points
    2024-09-19T08:55:18.4266667+00:00

    It turns out, Azure backend got confused by concurring "Create" and "Drop" operations because I might have messed up somewhere in the beginning. Due to this, the database name I chose was already in use and Azure could not create the flexible Postgres server. Simply changing the name of the server seems to have fixed it.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.