Skip to content

Commit

Permalink
feat: Add failover groups to avm/res/sql/server (#3881)
Browse files Browse the repository at this point in the history
## Description

This PR adds support for failover groups for the `avm/res/sql/server`
module.

Fixes #3609

Questions:
* In the failover group test, I have a dependency (the secondary SQL
Server): should I move that to a separate dependencies module, or is it
OK to have it in the main test file?
* The test contains hard-coded locations to ensure proper region pairs.
Is that the preferred way to override location?
* Should I extend `max` and/or `waf` test with this module?

## Pipeline Reference

<!-- Insert your Pipeline Status Badge below -->

| Pipeline |
| -------- |
|
[![avm.res.sql.server](https://github.com/peterbud/bicep-registry-modules/actions/workflows/avm.res.sql.server.yml/badge.svg)](https://github.com/peterbud/bicep-registry-modules/actions/workflows/avm.res.sql.server.yml)
|

Pls note I don't have Maintenance Window available in my sbscription.

## Type of Change

<!-- Use the checkboxes [x] on the options that are relevant. -->

- [ ] Update to CI Environment or utilities (Non-module affecting
changes)
- [ ] Azure Verified Module updates:
- [ ] Bugfix containing backwards-compatible bug fixes, and I have NOT
bumped the MAJOR or MINOR version in `version.json`:
- [x] Someone has opened a bug report issue, and I have included "Closes
#{bug_report_issue_number}" in the PR description.
- [ ] The bug was found by the module author, and no one has opened an
issue to report it yet.
- [x] Feature update backwards compatible feature updates, and I have
bumped the MINOR version in `version.json`.
- [ ] Breaking changes and I have bumped the MAJOR version in
`version.json`.
  - [ ] Update to documentation

## Checklist

- [x] I'm sure there are no other open Pull Requests for the same
update/change
- [x] I have run `Set-AVMModule` locally to generate the supporting
module files.
- [x] My corresponding pipelines / checks run clean and green without
any errors or warnings

<!-- Please keep up to date with the contribution guide at
https://aka.ms/avm/contribute/bicep -->
  • Loading branch information
peterbud authored Dec 20, 2024
1 parent 701814f commit dbc446e
Show file tree
Hide file tree
Showing 19 changed files with 1,501 additions and 146 deletions.
463 changes: 453 additions & 10 deletions avm/res/sql/server/README.md

Large diffs are not rendered by default.

13 changes: 5 additions & 8 deletions avm/res/sql/server/audit-settings/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.31.92.45157",
"templateHash": "4626140114742164628"
"version": "0.32.4.45862",
"templateHash": "14061468320361890476"
},
"name": "Azure SQL Server Audit Settings",
"description": "This module deploys an Azure SQL Server Audit Settings.",
Expand Down Expand Up @@ -123,10 +123,7 @@
"storageAccountAccessKey": "[if(and(not(empty(parameters('storageAccountResourceId'))), not(parameters('isManagedIdentityInUse'))), listKeys(parameters('storageAccountResourceId'), '2019-06-01').keys[0].value, null())]",
"storageAccountSubscriptionId": "[if(not(empty(parameters('storageAccountResourceId'))), split(parameters('storageAccountResourceId'), '/')[2], null())]",
"storageEndpoint": "[if(not(empty(parameters('storageAccountResourceId'))), format('https://{0}.blob.{1}', last(split(parameters('storageAccountResourceId'), '/')), environment().suffixes.storage), null())]"
},
"dependsOn": [
"server"
]
}
},
"storageAccount_sbdc_rbac": {
"condition": "[and(parameters('isManagedIdentityInUse'), not(empty(parameters('storageAccountResourceId'))))]",
Expand All @@ -152,8 +149,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.31.92.45157",
"templateHash": "2903956714854050681"
"version": "0.32.4.45862",
"templateHash": "12732093554587495593"
}
},
"parameters": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.31.92.45157",
"templateHash": "3060709558343951533"
"version": "0.32.4.45862",
"templateHash": "1446282995445489550"
},
"name": "SQL Server Database Long Term Backup Retention Policies",
"description": "This module deploys an Azure SQL Server Database Long-Term Backup Retention Policy.",
Expand Down Expand Up @@ -77,10 +77,7 @@
"existing": true,
"type": "Microsoft.Sql/servers/databases",
"apiVersion": "2023-08-01-preview",
"name": "[format('{0}/{1}', parameters('serverName'), parameters('databaseName'))]",
"dependsOn": [
"server"
]
"name": "[format('{0}/{1}', parameters('serverName'), parameters('databaseName'))]"
},
"server": {
"existing": true,
Expand All @@ -99,10 +96,7 @@
"weeklyRetention": "[parameters('weeklyRetention')]",
"weekOfYear": "[parameters('weekOfYear')]",
"yearlyRetention": "[parameters('yearlyRetention')]"
},
"dependsOn": [
"server::database"
]
}
}
},
"outputs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.31.92.45157",
"templateHash": "1465086214783345027"
"version": "0.32.4.45862",
"templateHash": "2726045612900421237"
},
"name": "Azure SQL Server Database Short Term Backup Retention Policies",
"description": "This module deploys an Azure SQL Server Database Short-Term Backup Retention Policy.",
Expand Down
27 changes: 9 additions & 18 deletions avm/res/sql/server/database/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.31.92.45157",
"templateHash": "10088627667414343400"
"version": "0.32.4.45862",
"templateHash": "8657415553449823149"
},
"name": "SQL Server Database",
"description": "This module deploys an Azure SQL Server Database.",
Expand Down Expand Up @@ -645,10 +645,7 @@
"sourceResourceId": "[parameters('sourceResourceId')]",
"useFreeLimit": "[parameters('useFreeLimit')]",
"zoneRedundant": "[parameters('zoneRedundant')]"
},
"dependsOn": [
"server"
]
}
},
"database_diagnosticSettings": {
"copy": {
Expand Down Expand Up @@ -721,8 +718,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.31.92.45157",
"templateHash": "1465086214783345027"
"version": "0.32.4.45862",
"templateHash": "2726045612900421237"
},
"name": "Azure SQL Server Database Short Term Backup Retention Policies",
"description": "This module deploys an Azure SQL Server Database Short-Term Backup Retention Policy.",
Expand Down Expand Up @@ -839,8 +836,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.31.92.45157",
"templateHash": "3060709558343951533"
"version": "0.32.4.45862",
"templateHash": "1446282995445489550"
},
"name": "SQL Server Database Long Term Backup Retention Policies",
"description": "This module deploys an Azure SQL Server Database Long-Term Backup Retention Policy.",
Expand Down Expand Up @@ -911,10 +908,7 @@
"existing": true,
"type": "Microsoft.Sql/servers/databases",
"apiVersion": "2023-08-01-preview",
"name": "[format('{0}/{1}', parameters('serverName'), parameters('databaseName'))]",
"dependsOn": [
"server"
]
"name": "[format('{0}/{1}', parameters('serverName'), parameters('databaseName'))]"
},
"server": {
"existing": true,
Expand All @@ -933,10 +927,7 @@
"weeklyRetention": "[parameters('weeklyRetention')]",
"weekOfYear": "[parameters('weekOfYear')]",
"yearlyRetention": "[parameters('yearlyRetention')]"
},
"dependsOn": [
"server::database"
]
}
}
},
"outputs": {
Expand Down
9 changes: 3 additions & 6 deletions avm/res/sql/server/elastic-pool/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.31.92.45157",
"templateHash": "9050866823207809352"
"version": "0.32.4.45862",
"templateHash": "9155929618024075319"
},
"name": "SQL Server Elastic Pool",
"description": "This module deploys an Azure SQL Server Elastic Pool.",
Expand Down Expand Up @@ -251,10 +251,7 @@
"perDatabaseSettings": "[if(not(empty(parameters('perDatabaseSettings'))), createObject('autoPauseDelay', tryGet(parameters('perDatabaseSettings'), 'autoPauseDelay'), 'maxCapacity', json(tryGet(parameters('perDatabaseSettings'), 'maxCapacity')), 'minCapacity', json(tryGet(parameters('perDatabaseSettings'), 'minCapacity'))), null())]",
"preferredEnclaveType": "[parameters('preferredEnclaveType')]",
"zoneRedundant": "[parameters('zoneRedundant')]"
},
"dependsOn": [
"server"
]
}
}
},
"outputs": {
Expand Down
4 changes: 2 additions & 2 deletions avm/res/sql/server/encryption-protector/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.31.92.45157",
"templateHash": "3436938593239210559"
"version": "0.32.4.45862",
"templateHash": "16275612719201291134"
},
"name": "Azure SQL Server Encryption Protector",
"description": "This module deploys an Azure SQL Server Encryption Protector.",
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. |
Loading

0 comments on commit dbc446e

Please sign in to comment.