Create Microsoft SQL Server With Bicep

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/[email protected]' = {
  name: 'ntweeklysql1'
  location: location
  
  identity: {
    type:   'none'
    userAssignedIdentities: { }
  }
  properties: {
    administratorLogin: adminUsername
    administratorLoginPassword: adminPassword
    administrators: {
      administratorType:  'ActiveDirectory'
      azureADOnlyAuthentication: false
      login:  '[email protected]'
      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.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.