In this blog post, we will deploy a Microsoft SQL Server in Azure using the Bicep infrastructure-as-code language.
Bicep Template
The following template will deploy an MS SQL Server in Microsoft Azure.
A few notes about the template:
- The authentication type is set to SQL and Azure AD
- Line 22 sets the Azure AD user or group SQL DB admin
- You will need to get the Azure AD username (of user or group), SID and your Azure AD tenant ID. You will find the user SID in the user properties in Azure AD.
- Your Azure AD tenant ID is located on the Azure AD console overview page
- The SQL admin password set in the template is configured to use a secure string.
param location string = resourceGroup().location
param adminUsername string
@secure()
param adminPassword string
resource sqlserver 'Microsoft.Sql/servers@2022-05-01-preview' = {
name: 'ntweeklysql1'
location: location
identity: {
type: 'none'
userAssignedIdentities: { }
}
properties: {
administratorLogin: adminUsername
administratorLoginPassword: adminPassword
administrators: {
administratorType: 'ActiveDirectory'
azureADOnlyAuthentication: false
login: 'SQLADMIN@emailaddress'
principalType: 'User'
sid: 'SQLADMIN_Azure_AD_SID'
tenantId: 'Azure_AD_Tenant_ID'
}
}
}
Run Template
Use the following cmd to run the template and pass the SQL server username and password.
az deployment group create --template-file 19.Windows_VM.bicep --resource-group biceplab --parameters adminUsername=SQLADMINNAME adminPassword=SETPASSWORD --verbose
Processing…
Success! You're on the list.
Whoops! There was an error and we couldn't process your subscription. Please reload the page and try again.