Share via

Terraform plan - PostgreSQL Flexible Server: 502 Bad Gateway - ServerUnableToRetriveData

Rens Oostenbach 40 Reputation points
2026-01-21T11:06:46.68+00:00

My terraform plan is failing because of a PostgreSQL flexible server returning a 502 error:

Error: retrieving Database (Subscription: "[MASKED]"

│ Resource Group Name: "xxx"

│ Flexible Server Name: "xxx"

│ Database Name: "xxx"): unexpected status 502 (502 Bad Gateway) with error: ServerUnableToRetriveData: Server encountered an issue while trying to retrieve some data. Try again later.

The PostgreSQL Flexible Server is in West Europe. Within our subscription, we have multiple other PostgreSQL Flexible Servers in West Europe for which the terraform plan does work normally.

I came across these two articles:

And it seems like my issue is very similar. The first article mentions to create a support ticket. I hope that getting into contact with a Microsoft support employee will fix the problem we have with our specific postgresql flexible server.

Azure Database for PostgreSQL
0 comments No comments

Answer accepted by question author

Manoj Kumar Boyini 16,810 Reputation points Microsoft External Staff Moderator
2026-01-21T12:29:27.4933333+00:00

Hi Rens Oostenbach,

The PostgreSQL Flexible Server was accessible for normal database operations, but Terraform plan executions were failing, which caused CI/CD pipeline errors. Direct connections to the server and databases were working as expected. The issue started after a SKU change attempt on January 19.

During validation, we confirmed that all databases and data were intact, and there were no data-level issues. To stabilize the environment, the compute tier was temporarily changed from Burstable to General Purpose, which triggered a server restart. Once the server returned to a ready state, the databases were visible in the Azure portal and the Terraform connection issue was no longer reproducible.

This indicates the issue was likely caused by an inconsistent server state following the earlier SKU change operation, rather than a configuration or data problem.

Next steps:

The plan is to downgrade back to the preferred Burstable SKU and monitor the server behavior.

If the issue reoccurs after the downgrade, please follow up here and we can investigate further.

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Sina Salam 29,846 Reputation points Volunteer Moderator
    2026-01-23T12:05:37.0033333+00:00

    Hello Rens Oostenbach,

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    I understand that your Terraform plan - PostgreSQL Flexible Server is having 502 Bad Gateway - ServerUnableToRetriveData.

    The 502 / ServerUnableToRetrieveData error during Terraform refresh or plan is caused by an intermittent Azure control-plane (ARM) failure in the Microsoft.DBforPostgreSQL resource provider when retrieving Flexible Server metadata. It is not related to quotas, permissions, or Terraform configuration, and the same code often works in other regions or subscriptions.

    What to do:

    • Temporarily deploy to a known-healthy region if feasible.
    • Use terraform plan -refresh=false only when you are confident there is no state drift.
    • Temporarily remove only the failing PostgreSQL Flexible Server or database from Terraform state (terraform state rm) and re-import it once the Azure API stabilizes.
    • As a stopgap, use the AzAPI provider for read-only metadata access where appropriate.

    After recovery, restore normal refresh and plan behavior to reconcile Terraform state with Azure. https://github.com/hashicorp/terraform-provider-azurerm/issues/30749?utm_source=chatgpt.com, https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/postgresql_flexible_server?utm_source=chatgpt.com, and https://learn.microsoft.com/en-us/azure/developer/terraform/deploy-postgresql-flexible-server-database?utm_source=chatgpt.com links provides more details.

    I hope this is helpful! Do not hesitate to let me know if you have any other questions or clarifications.


    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.

    Was this answer helpful?


Your answer

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