hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.46k stars 4.55k forks source link

Azure Database Flexible PostgreSQL : Failed to provision multiple Read-Replicas #22211

Open tgrevillot opened 1 year ago

tgrevillot commented 1 year ago

Is there an existing issue for this?

Community Note

Terraform Version

1.4.6

AzureRM Provider Version

3.61.0

Affected Resource(s)/Data Source(s)

azurerm_postgresql_flexible_server

Terraform Configuration Files

resource "azurerm_postgresql_flexible_server" "main_server" {
  name                         = "main-server"
  location                     = data.azurerm_resource_group.rg.location
  resource_group_name          = "my-rg"
  administrator_login          = "admin"
  administrator_password       = random_password.admin.result
  sku_name                     = "GP_Standard_D4s_v3"
  version                      = "14"
  storage_mb                   = "131072"
  delegated_subnet_id          = var.delegated_subnet
  private_dns_zone_id          = var.private_dns_zone
  backup_retention_days        = var.backup_retention_days
  geo_redundant_backup_enabled = False
}

resource "azurerm_postgresql_flexible_server" "replicas_servers" {
  count                        = 2
  name                         = join("-", ["replica", count.index])
  location                     = data.azurerm_resource_group.rg.location
  resource_group_name          = var.azure_resource_group
  administrator_login          = "admin"
  administrator_password       = random_password.owner.result
  sku_name                     = var.sku_name
  version                      = 14
  storage_mb                   = 131072
  delegated_subnet_id          = var.delegated_subnet
  private_dns_zone_id          = var.private_dns_zone
  backup_retention_days        = var.backup_retention_days
  geo_redundant_backup_enabled = False
  create_mode                  = "Replica"
  source_server_id             = azurerm_postgresql_flexible_server.main_server.id
}

Debug Output/Panic Output

╷
│ Error: creating Flexible Server (Subscription: "xxxxxxxx"
│ Resource Group Name: "xxxxxxxx"
│ Flexible Server Name: "replica-1"): polling after Create: Code="InternalServerError" Message="An unexpected error occured while processing the request. Tracking ID: 'xxxxxxxx'"
│ 
│   with module.azure_postgres.azurerm_postgresql_flexible_server.replicas_servers[1],
│   on ../main.tf line XX, in resource "azurerm_postgresql_flexible_server" "replicas_servers":
│  XX: resource "azurerm_postgresql_flexible_server" "replicas_servers" {
│ 
╵
╷
│ Error: creating Flexible Server (Subscription: "xxxxxxxx"
│ Resource Group Name: "xxxxxxxx"
│ Flexible Server Name: "replica-2"): polling after Create: Code="InternalServerError" Message="An unexpected error occured while processing the request. Tracking ID: 'xxxxxxxx'"
│ 
│   with module.azure_postgres.azurerm_postgresql_flexible_server.replicas_servers[2],
│   on ../main.tf line XX, in resource "azurerm_postgresql_flexible_server" "replicas_servers":
│  XX: resource "azurerm_postgresql_flexible_server" "replicas_servers" {
│ 
╵

Expected Behaviour

Main PostgreSQL Flexible Server and its 2 replica should have been created.

Actual Behaviour

Actually the first Read-replica is correctly created but both of other replicas requests are rejected (after around 1min30) and failed with this error 500.

After several tests, it seems that the only way to create multiple Read-Replicas with terraform is to do it sequentially, which is impossible to do with a "count operation" (because all operations are done in parallells) currently.

The only workaround for this issue that I found until now is to set the "-parallelism" argument of terraform CLI to 1 (which force Terraform to not create multiple resources on parallel).

But this is not a satisfying solution and I want like to know if anyone here already encountered the same issue or if I misunderstand something in these concepts.

Steps to Reproduce

Important Factoids

No response

References

No response

neil-yechenwei commented 1 year ago

Thanks for raising this issue. It has to wait at least 15 minutes until the configuration of source server is ready before creating replica server. And service team confirmed that it only supports creating read replica servers in sequence.

tgrevillot commented 1 year ago

Thanks for your answer. Do you know if this issue is on the roadmap ? Because this is a feature we would like to use.

Oluseyiblessed commented 5 months ago

I still experience the same issue. On the portal the collation and charset not update and terraform wants to redeploy new databases and delete the current databases. Please when will this issue be fixed.

julienmourgues commented 4 months ago

I still experience the same issue.