Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Bicep - sql-vm-ag-setup #13782

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ products:
- azure-resource-manager
urlFragment: sql-vm-ag-setup
languages:
- bicep
- json
---
# Deploy SQL Always ON setup with existing SQL Virtual Machines
Expand All @@ -19,6 +20,8 @@ languages:
![Best Practice Check](https://azurequickstartsservice.blob.core.windows.net/badges/quickstarts/microsoft.sqlvirtualmachine/sql-vm-ag-setup/BestPracticeResult.svg)
![Cred Scan Check](https://azurequickstartsservice.blob.core.windows.net/badges/quickstarts/microsoft.sqlvirtualmachine/sql-vm-ag-setup/CredScanResult.svg)

![Bicep Version](https://azurequickstartsservice.blob.core.windows.net/badges/quickstarts/microsoft.sqlvirtualmachine/sql-vm-ag-setup/BicepVersion.svg)

Before deploying the template you must have the following

1. **Domain** Domain must exist in which the underlying Windows Server Failover Cluster will be created
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@
},
"cloudWitnessName": {
"value": "GEN-UNIQUE"
},
"location": {
"value": "GEN-UNIQUE"
}

}
}
110 changes: 110 additions & 0 deletions quickstarts/microsoft.sqlvirtualmachine/sql-vm-ag-setup/main.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
@description('Specify the Windows Failover Cluster Name')
@maxLength(15)
param failoverClusterName string

@description('Specify comma separated list of names of SQL Server VM\'s to participate in the Availability Group (e.g. SQLVM1, SQLVM2). OS underneath should be at least WS 2016.')
param existingVmList string

@description('Specify the SQL Server License type for all VM\'s.')
@allowed([
'PAYG'
'AHUB'
])
param sqlServerLicenseType string

@description('Specify resourcegroup name for existing Vms.')
param existingVmResourceGroup string = resourceGroup().name

@description('Select the version of SQL Server Image type')
@allowed([
'sql2017-ws2019'
'sql2019-WS2019'
'sql2019-ws2022'
])
param sqlServerImageType string = 'sql2019-ws2022'

@description('Specify the Fully Qualified Domain Name under which the Failover Cluster will be created. The VM\'s should already be joined to it. (e.g. contoso.com)')
param existingFullyQualifiedDomainName string

@description('Specify an optional Organizational Unit (OU) on AD Domain where the CNO (Computer Object for Cluster Name) will be created (e.g. OU=testou,OU=testou2,DC=contoso,DC=com). Default is empty.')
param existingOuPath string = ''

@description('Specify the account for WS failover cluster creation in UPN format (e.g. [email protected]). This account can either be a Domain Admin or at least have permissions to create Computer Objects in default or specified OU.')
param existingDomainAccount string

@description('Specify the password for the domain account')
@secure()
param domainAccountPassword string

@description('Specify the domain account under which SQL Server service will run for AG setup in UPN format (e.g. [email protected])')
param existingSqlServiceAccount string

@description('Specify the password for Sql Server service account')
@secure()
param sqlServicePassword string

@description('Specify the name of the storage account to be used for creating Cloud Witness for Windows server failover cluster')
param cloudWitnessName string = 'clwitness${uniqueString(resourceGroup().id)}'

@description('Location for all resources.')
param location string = resourceGroup().location

var existingVMList = split(existingVmList, ',')
var GroupResourceId = failoverCluster.id

resource sqlVM 'Microsoft.SqlVirtualMachine/SqlVirtualMachines@2022-08-01-preview' = [for item in existingVMList: {
name: trim(item)
location: location
properties: {
virtualMachineResourceId: resourceId(existingVmResourceGroup, 'Microsoft.Compute/virtualMachines', trim(item))
sqlServerLicenseType: sqlServerLicenseType
}
}]

resource cloudWitness 'Microsoft.Storage/storageAccounts@2022-09-01' = {
name: cloudWitnessName
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
location: location
properties: {
accessTier: 'Hot'
supportsHttpsTrafficOnly: true
}
}

resource failoverCluster 'Microsoft.SqlVirtualMachine/SqlVirtualMachineGroups@2022-08-01-preview' = {
name: failoverClusterName
location: location
properties: {
sqlImageOffer: sqlServerImageType
sqlImageSku: 'Enterprise'
wsfcDomainProfile: {
domainFqdn: existingFullyQualifiedDomainName
ouPath: existingOuPath
clusterBootstrapAccount: existingDomainAccount
clusterOperatorAccount: existingDomainAccount
sqlServiceAccount: existingSqlServiceAccount
storageAccountUrl: cloudWitness.properties.primaryEndpoints.blob
storageAccountPrimaryKey: cloudWitness.listKeys().keys[0].value
}
}
}

module joincluster 'modules/join-cluster.bicep' = {
name: 'joincluster'
params: {
existingVirtualMachineNames: existingVMList
location: location
sqlServerLicenseType: sqlServerLicenseType
existingVmResourceGroup: existingVmResourceGroup
groupResourceId: GroupResourceId
domainAccountPassword: domainAccountPassword
sqlServicePassword: sqlServicePassword
}
dependsOn: [
cloudWitness
sqlVM
]
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"$schema": "https://aka.ms/azure-quickstart-templates-metadata-schema#",
"type": "QuickStart",
"itemDisplayName": "Deploy SQL Always ON setup with existing SQL Virtual Machines",
"itemDisplayName": "Deploy SQL Always ON setup with existing SQL VM",
"description": "Deploy SQL Always ON setup with existing SQL Virtual Machines. The virtual machines should already be joined to an existing domain and must be running enterprise version of SQL Server.",
"summary": "Deploy SQL Always ON setup with existing SQL Virtual Machines.",
"githubUsername": "pratraw",
"dateUpdated": "2023-06-01"
"dateUpdated": "2024-02-21"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
param location string
param existingVirtualMachineNames array
param sqlServerLicenseType string
param existingVmResourceGroup string
param groupResourceId string

@secure()
param domainAccountPassword string

@secure()
param sqlServicePassword string

resource existingVirtualMachine 'Microsoft.SqlVirtualMachine/SqlVirtualMachines@2022-08-01-preview' = [for item in existingVirtualMachineNames: {
name: trim(item)
location: location
properties: {
virtualMachineResourceId: resourceId(existingVmResourceGroup, 'Microsoft.Compute/virtualMachines', trim(item))
sqlServerLicenseType: sqlServerLicenseType
sqlVirtualMachineGroupResourceId: groupResourceId
wsfcDomainCredentials: {
clusterBootstrapAccountPassword: domainAccountPassword
clusterOperatorAccountPassword: domainAccountPassword
sqlServiceAccountPassword: sqlServicePassword
}
}
}]