forked from Azure/bicep-registry-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add failover groups to SQL Server
- Loading branch information
Showing
17 changed files
with
1,428 additions
and
33 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
# Azure SQL Server failover group `[Microsoft.Sql/servers/failoverGroups]` | ||
|
||
This module deploys Azure SQL Server failover group. | ||
|
||
## Navigation | ||
|
||
- [Resource Types](#Resource-Types) | ||
- [Parameters](#Parameters) | ||
- [Outputs](#Outputs) | ||
|
||
## Resource Types | ||
|
||
| Resource Type | API Version | | ||
| :-- | :-- | | ||
| `Microsoft.Sql/servers/failoverGroups` | [2024-05-01-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Sql/2024-05-01-preview/servers/failoverGroups) | | ||
|
||
## Parameters | ||
|
||
**Required parameters** | ||
|
||
| Parameter | Type | Description | | ||
| :-- | :-- | :-- | | ||
| [`databases`](#parameter-databases) | array | List of databases in the failover group. | | ||
| [`name`](#parameter-name) | string | The name of the failover group. | | ||
| [`partnerServers`](#parameter-partnerservers) | array | List of the partner servers for the failover group. | | ||
| [`readWriteEndpoint`](#parameter-readwriteendpoint) | object | Read-write endpoint of the failover group instance. | | ||
| [`secondaryType`](#parameter-secondarytype) | string | Databases secondary type on partner server. | | ||
|
||
**Conditional parameters** | ||
|
||
| Parameter | Type | Description | | ||
| :-- | :-- | :-- | | ||
| [`serverName`](#parameter-servername) | string | The Name of SQL Server. Required if the template is used in a standalone deployment. | | ||
|
||
**Optional parameters** | ||
|
||
| Parameter | Type | Description | | ||
| :-- | :-- | :-- | | ||
| [`readOnlyEndpoint`](#parameter-readonlyendpoint) | object | Read-only endpoint of the failover group instance. | | ||
|
||
### Parameter: `databases` | ||
|
||
List of databases in the failover group. | ||
|
||
- Required: Yes | ||
- Type: array | ||
|
||
### Parameter: `name` | ||
|
||
The name of the failover group. | ||
|
||
- Required: Yes | ||
- Type: string | ||
|
||
### Parameter: `partnerServers` | ||
|
||
List of the partner servers for the failover group. | ||
|
||
- Required: Yes | ||
- Type: array | ||
|
||
### Parameter: `readWriteEndpoint` | ||
|
||
Read-write endpoint of the failover group instance. | ||
|
||
- Required: Yes | ||
- Type: object | ||
|
||
**Required parameters** | ||
|
||
| Parameter | Type | Description | | ||
| :-- | :-- | :-- | | ||
| [`failoverPolicy`](#parameter-readwriteendpointfailoverpolicy) | string | Failover policy of the read-write endpoint for the failover group. If failoverPolicy is Automatic then failoverWithDataLossGracePeriodMinutes is required. | | ||
|
||
**Optional parameters** | ||
|
||
| Parameter | Type | Description | | ||
| :-- | :-- | :-- | | ||
| [`failoverWithDataLossGracePeriodMinutes`](#parameter-readwriteendpointfailoverwithdatalossgraceperiodminutes) | int | Grace period before failover with data loss is attempted for the read-write endpoint. | | ||
|
||
### Parameter: `readWriteEndpoint.failoverPolicy` | ||
|
||
Failover policy of the read-write endpoint for the failover group. If failoverPolicy is Automatic then failoverWithDataLossGracePeriodMinutes is required. | ||
|
||
- Required: Yes | ||
- Type: string | ||
- Allowed: | ||
```Bicep | ||
[ | ||
'Automatic' | ||
'Manual' | ||
] | ||
``` | ||
|
||
### Parameter: `readWriteEndpoint.failoverWithDataLossGracePeriodMinutes` | ||
|
||
Grace period before failover with data loss is attempted for the read-write endpoint. | ||
|
||
- Required: No | ||
- Type: int | ||
|
||
### Parameter: `secondaryType` | ||
|
||
Databases secondary type on partner server. | ||
|
||
- Required: Yes | ||
- Type: string | ||
- Allowed: | ||
```Bicep | ||
[ | ||
'Geo' | ||
'Standby' | ||
] | ||
``` | ||
|
||
### Parameter: `serverName` | ||
|
||
The Name of SQL Server. Required if the template is used in a standalone deployment. | ||
|
||
- Required: Yes | ||
- Type: string | ||
|
||
### Parameter: `readOnlyEndpoint` | ||
|
||
Read-only endpoint of the failover group instance. | ||
|
||
- Required: No | ||
- Type: object | ||
|
||
**Required parameters** | ||
|
||
| Parameter | Type | Description | | ||
| :-- | :-- | :-- | | ||
| [`failoverPolicy`](#parameter-readonlyendpointfailoverpolicy) | string | Failover policy of the read-only endpoint for the failover group. | | ||
| [`targetServer`](#parameter-readonlyendpointtargetserver) | string | The target partner server where the read-only endpoint points to. | | ||
|
||
### Parameter: `readOnlyEndpoint.failoverPolicy` | ||
|
||
Failover policy of the read-only endpoint for the failover group. | ||
|
||
- Required: Yes | ||
- Type: string | ||
- Allowed: | ||
```Bicep | ||
[ | ||
'Disabled' | ||
'Enabled' | ||
] | ||
``` | ||
|
||
### Parameter: `readOnlyEndpoint.targetServer` | ||
|
||
The target partner server where the read-only endpoint points to. | ||
|
||
- Required: Yes | ||
- Type: string | ||
|
||
## Outputs | ||
|
||
| Output | Type | Description | | ||
| :-- | :-- | :-- | | ||
| `name` | string | The name of the deployed failover group. | | ||
| `resourceGroupName` | string | The resource group of the deployed failover group. | | ||
| `resourceId` | string | The resource ID of the deployed failover group. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
metadata name = 'Azure SQL Server failover group' | ||
metadata description = 'This module deploys Azure SQL Server failover group.' | ||
metadata owner = 'Azure/module-maintainers' | ||
|
||
@description('Required. The name of the failover group.') | ||
param name string | ||
|
||
@description('Conditional. The Name of SQL Server. Required if the template is used in a standalone deployment.') | ||
param serverName string | ||
|
||
@description('Required. List of databases in the failover group.') | ||
param databases string[] | ||
|
||
@description('Required. List of the partner servers for the failover group.') | ||
param partnerServers string[] | ||
|
||
@description('Optional. Read-only endpoint of the failover group instance.') | ||
param readOnlyEndpoint FailoverGroupReadOnlyEndpointType? | ||
|
||
@description('Required. Read-write endpoint of the failover group instance.') | ||
param readWriteEndpoint FailoverGroupReadWriteEndpointType | ||
|
||
@description('Required. Databases secondary type on partner server.') | ||
param secondaryType 'Geo' | 'Standby' | ||
|
||
resource server 'Microsoft.Sql/servers@2023-08-01-preview' existing = { | ||
name: serverName | ||
} | ||
|
||
// https://stackoverflow.com/questions/78337117/azure-sql-failover-group-fails-on-second-run | ||
// https://github.com/Azure/bicep-types-az/issues/2153 | ||
|
||
resource failoverGroup 'Microsoft.Sql/servers/failoverGroups@2024-05-01-preview' = { | ||
name: name | ||
parent: server | ||
properties: { | ||
databases: [for db in databases: resourceId('Microsoft.Sql/servers/databases', serverName, db)] | ||
partnerServers: [ | ||
for partnerServer in partnerServers: { | ||
id: resourceId(resourceGroup().name, 'Microsoft.Sql/servers', partnerServer) | ||
} | ||
] | ||
readOnlyEndpoint: !empty(readOnlyEndpoint) | ||
? { | ||
failoverPolicy: readOnlyEndpoint!.failoverPolicy | ||
targetServer: resourceId(resourceGroup().name, 'Microsoft.Sql/servers', readOnlyEndpoint!.targetServer) | ||
} | ||
: null | ||
readWriteEndpoint: readWriteEndpoint | ||
secondaryType: secondaryType | ||
} | ||
} | ||
|
||
// =============== // | ||
// Outputs // | ||
// =============== // | ||
|
||
@description('The name of the deployed failover group.') | ||
output name string = failoverGroup.name | ||
|
||
@description('The resource ID of the deployed failover group.') | ||
output resourceId string = failoverGroup.id | ||
|
||
@description('The resource group of the deployed failover group.') | ||
output resourceGroupName string = resourceGroup().name | ||
|
||
@export() | ||
type FailoverGroupReadOnlyEndpointType = { | ||
@description('Required. Failover policy of the read-only endpoint for the failover group.') | ||
failoverPolicy: 'Disabled' | 'Enabled' | ||
|
||
@description('Required. The target partner server where the read-only endpoint points to.') | ||
targetServer: string | ||
} | ||
|
||
@export() | ||
type FailoverGroupReadWriteEndpointType = { | ||
@description('Required. Failover policy of the read-write endpoint for the failover group. If failoverPolicy is Automatic then failoverWithDataLossGracePeriodMinutes is required.') | ||
failoverPolicy: 'Automatic' | 'Manual' | ||
|
||
@description('Optional. Grace period before failover with data loss is attempted for the read-write endpoint.') | ||
failoverWithDataLossGracePeriodMinutes: int? | ||
} |
Oops, something went wrong.