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
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.