Is it safe to change the version number of an Azure resource in Terraform after upgrading through Azure Portal

Victor Udnæs 5 Reputation points
2025-11-01T14:46:15.41+00:00

I recently used the Azure Portal to do a major version upgrade of my Azure PostgreSQL Server from v 13 to 14. That worked fine, but we also have a Terraform config for all resources in our cluster that's still defined as v13. I know that i probably should have upgraded it entierly through Terraform, but i didnt want the Terraform job to delete the db and recreate it again and have to migrate backup data into it manually. If i now just change the version to 14 in the Terraform script, will it trigger a complete redeploy of the database or will it recognize that the existing database is already v14 and leave it alone?

Azure Database for PostgreSQL
{count} vote

1 answer

Sort by: Most helpful
  1. Mahesh Kurva 10,520 Reputation points Microsoft External Staff Moderator
    2025-11-03T13:30:10.97+00:00

    Hi Victor Udnæs ,

    Greetings!!

    It sounds like you’re in a tricky spot with your Azure PostgreSQL Server and Terraform setup. When you upgrade your PostgreSQL server manually through the Azure Portal but your Terraform configuration still references the old version, Terraform’s state and the actual resource can get out of sync.

    It’s important to know that for Azure PostgreSQL, the version field in Terraform is marked as ForceNew. This means if you simply change the version in your Terraform configuration (e.g., from 13 to 14), Terraform will plan to destroy and recreate the server even if the actual server is already on version 14.

    To avoid accidental deletion or data loss, you can:

    Import or refresh the resource state so Terraform recognizes the live configuration:

    terraform import azurerm_postgresql_flexible_server.myserver /subscriptions/<sub_id>/resourceGroups/<rg_name>/providers/Microsoft.DBforPostgreSQL/flexibleServers/<server_name>
    

    Update your Terraform config to use version = "14".

    Run terraform plan and verify that no destroy or replace actions are planned.

    For more information, please refer the document:

    https://github.com/Azure/terraform-azurerm-avm-res-dbforpostgresql-flexibleserver

    https://docs.azure.cn/en-us/postgresql/flexible-server/concepts-major-version-upgrade?utm_source=chatgpt.com

    Hope this helps. Do let us know if you have any further queries.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.

    0 comments No comments

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.