I’ve setup an AzureSQL failover group using a bicep, with very simple settings. The first deployment works as expected. If I deploy again, without making any changes, I get this error:
The property targetServer of the read-only endpoint must be a valid server present among the partnerServers configured for the failover group.
The second run uses the same servers as before, and all should be valid.
I’m not sure what this is telling me?
Here is my bicep:
param failoverGroupName string
param primarySqlServerName string
param secondarySqlServerName string
param databaseName string
param secondaryResourceGroup string
resource primary 'Microsoft.Sql/servers@2022-08-01-preview' existing = {
name: primarySqlServerName
}
resource secondary 'Microsoft.Sql/servers@2022-08-01-preview' existing = {
name: secondarySqlServerName
scope: resourceGroup(secondaryResourceGroup)
}
resource sqlServerFailoverGroup 'Microsoft.Sql/servers/failoverGroups@2023-05-01-preview' = {
name: failoverGroupName
parent: primary
properties: {
databases: [
resourceId('Microsoft.Sql/servers/databases', primarySqlServerName,databaseName)
]
readWriteEndpoint: {
failoverPolicy: 'Automatic'
failoverWithDataLossGracePeriodMinutes: 60
}
readOnlyEndpoint: {
failoverPolicy: 'Enabled'
}
partnerServers: [
{
id: secondary.id
}
]
}
}
2
Answers
I tried deploying the same code as given in this SO again and was able to deploy it as expected which is shown below.
Try clearing the cache and again deploy the whole bicep code. Or restore the bicep file with the respective path using
az bicep restore --file filename.bicep
so that it restores the file in the current environment.If still the issue persists, add
target server
(secondary server) property underreadOnlyEndpoint
as shown below to avoid your error.Deployment succeeded:
i still hit the same error even i added the targetServer for read only endpoint.
i have primary server and 2ndary server in different regions. the two vnet are peered up. not sure what else to try now.