Open leonrob opened 1 week ago
Hi @leonrob,
I’ve been looking into this issue, and after some hours, I’ve reached the conclusion that it may be problematic at this point to make any change.
When a server is created with create_mode = default, the replication_role is set to ‘Primary’ behind the scenes. When it is created with create_mode = Replica, it is set to AsyncReplica (or GeoAsyncReplica if it is in a different region). These values are set automatically by the Azure API, and any attempt to define something different will either be ignored or result in an error.
Now, the transition between Replica and Primary cannot be made through the API but by promoting the replica server. Only an AsyncReplica can be turned into None, and from there into Primary or AsyncReplica. The problem here is a reported bug; if you try to set the role to None, it is actually set as Primary, “breaking” the replica relationship between the servers. I tried with the azapi provider using the latest version of the API, but it fails to make the change.
So, considering the “problems” on Azure’s side and the restrictions on changes, I would say that it is not safe to implement this just yet (in fact, the current implementation does not work properly). If you still want to handle this with Terraform, you can try the following snippet, but I’m not sure if Azure will accept the modification:
resource "azapi_update_resource" "None" {
type = "Microsoft.DBForPostgreSql/flexibleServers@2023-06-01-preview"
resource_id = <replica server id>
body = {
properties = {
replicationRole = "None" // Role to set
}
}
}
It is tricky to explain, but I hope I made myself clear enough.
Is there an existing issue for this?
Community Note
Description
Hi Currently this is set to only allow 'NONE' https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/postgresql_flexible_server#replication_role
But I have a need for this to be in Terraform now. Can someone please add the options Microsoft has available below?
https://learn.microsoft.com/en-us/azure/templates/microsoft.dbforpostgresql/2022-03-08-preview/flexibleservers?pivots=deployment-language-bicep
New or Affected Resource(s)/Data Source(s)
azurerm_all
Potential Terraform Configuration
No response
References
No response