Skip to content

Commit

Permalink
feat: Add failover groups to SQL Server
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbud committed Dec 4, 2024
1 parent 92db45c commit 163dec2
Show file tree
Hide file tree
Showing 17 changed files with 1,428 additions and 33 deletions.
485 changes: 464 additions & 21 deletions avm/res/sql/server/README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion avm/res/sql/server/audit-settings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This module deploys an Azure SQL Server Audit Settings.
| Resource Type | API Version |
| :-- | :-- |
| `Microsoft.Authorization/roleAssignments` | [2022-04-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Authorization/2022-04-01/roleAssignments) |
| `Microsoft.Sql/servers/auditingSettings` | [2023-08-01-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Sql/servers/auditingSettings) |
| `Microsoft.Sql/servers/auditingSettings` | [2023-08-01-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Sql/2023-08-01-preview/servers/auditingSettings) |

## Parameters

Expand Down
4 changes: 2 additions & 2 deletions avm/res/sql/server/database/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ This module deploys an Azure SQL Server Database.
| Resource Type | API Version |
| :-- | :-- |
| `Microsoft.Insights/diagnosticSettings` | [2021-05-01-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Insights/2021-05-01-preview/diagnosticSettings) |
| `Microsoft.Sql/servers/databases` | [2023-08-01-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Sql/servers/databases) |
| `Microsoft.Sql/servers/databases` | [2023-08-01-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Sql/2023-08-01-preview/servers/databases) |
| `Microsoft.Sql/servers/databases/backupLongTermRetentionPolicies` | [2023-05-01-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Sql/2023-05-01-preview/servers/databases/backupLongTermRetentionPolicies) |
| `Microsoft.Sql/servers/databases/backupShortTermRetentionPolicies` | [2023-08-01-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Sql/servers/databases/backupShortTermRetentionPolicies) |
| `Microsoft.Sql/servers/databases/backupShortTermRetentionPolicies` | [2023-08-01-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Sql/2023-08-01-preview/servers/databases/backupShortTermRetentionPolicies) |

## Parameters

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This module deploys an Azure SQL Server Database Short-Term Backup Retention Pol

| Resource Type | API Version |
| :-- | :-- |
| `Microsoft.Sql/servers/databases/backupShortTermRetentionPolicies` | [2023-08-01-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Sql/servers/databases/backupShortTermRetentionPolicies) |
| `Microsoft.Sql/servers/databases/backupShortTermRetentionPolicies` | [2023-08-01-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Sql/2023-08-01-preview/servers/databases/backupShortTermRetentionPolicies) |

## Parameters

Expand Down
2 changes: 1 addition & 1 deletion avm/res/sql/server/elastic-pool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This module deploys an Azure SQL Server Elastic Pool.

| Resource Type | API Version |
| :-- | :-- |
| `Microsoft.Sql/servers/elasticPools` | [2023-08-01-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Sql/servers/elasticPools) |
| `Microsoft.Sql/servers/elasticPools` | [2023-08-01-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Sql/2023-08-01-preview/servers/elasticPools) |

## Parameters

Expand Down
2 changes: 1 addition & 1 deletion avm/res/sql/server/encryption-protector/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This module deploys an Azure SQL Server Encryption Protector.

| Resource Type | API Version |
| :-- | :-- |
| `Microsoft.Sql/servers/encryptionProtector` | [2023-08-01-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Sql/servers/encryptionProtector) |
| `Microsoft.Sql/servers/encryptionProtector` | [2023-08-01-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Sql/2023-08-01-preview/servers/encryptionProtector) |

## Parameters

Expand Down
164 changes: 164 additions & 0 deletions avm/res/sql/server/failover-group/README.md
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. |
83 changes: 83 additions & 0 deletions avm/res/sql/server/failover-group/main.bicep
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?
}
Loading

0 comments on commit 163dec2

Please sign in to comment.