| title | Create SQL Server VM using Bicep | |||
|---|---|---|---|---|
| description | Learn how to create a SQL Server on Azure Virtual Machine (VM) using Bicep. | |||
| author | adbadram | |||
| ms.author | adbadram | |||
| ms.date | 06/17/2022 | |||
| ms.service | virtual-machines-sql | |||
| ms.subservice | deployment | |||
| ms.topic | quickstart | |||
| ms.custom |
|
This quickstart shows you how to use Bicep to create an SQL Server on Azure Virtual Machine (VM).
Bicep is a domain-specific language (DSL) that uses declarative syntax to deploy Azure resources. It provides concise syntax, reliable type safety, and support for code reuse. Bicep offers the best authoring experience for your infrastructure-as-code solutions in Azure.
The SQL Server VM Bicep file requires the following:
- The latest version of the Azure CLI and/or PowerShell.
- A pre-configured resource group with a prepared virtual network and subnet.
- An Azure subscription. If you don't have one, create a free account before you begin.
The Bicep file used in this quickstart is from Azure Quickstart Templates.
:::code language="bicep" source="~/../quickstart-templates/quickstarts/microsoft.sqlvirtualmachine/sql-vm-new-storage/main.bicep":::
Five Azure resources are defined in the Bicep file:
- Microsoft.Network/publicIpAddresses: Creates a public IP address.
- Microsoft.Network/networkSecurityGroups: Creates a network security group.
- Microsoft.Network/networkInterfaces: Configures the network interface.
- Microsoft.Compute/virtualMachines: Creates a virtual machine in Azure.
- Microsoft.SqlVirtualMachine/SqlVirtualMachines: registers the virtual machine with the SQL IaaS Agent extension.
-
Save the Bicep file as main.bicep to your local computer.
-
Deploy the Bicep file using either Azure CLI or Azure PowerShell.
az deployment group create --resource-group exampleRG --template-file main.bicep --parameters existingSubnetName=<subnet-name> adminUsername=<admin-user> adminPassword=<admin-pass>New-AzResourceGroupDeployment -ResourceGroupName exampleRG -TemplateFile ./main.bicep -administratorLogin "<admin-login>" -adminUsername "<admin-user>" -adminPassword "<admin-pass>"
Make sure to replace the resource group name, exampleRG, with the name of your pre-configured resource group.
You're required to enter the following parameters:
- existingSubnetName: Replace <subnet-name> with the name of the subnet.
- adminUsername: Replace <admin-user> with the admin username of the VM.
You'll also be prompted to enter adminPassword.
Note
When the deployment finishes, you should see a message indicating the deployment succeeded.
Use the Azure portal, Azure CLI, or Azure PowerShell to list the deployed resources in the resource group.
az resource list --resource-group exampleRG
Get-AzResource -ResourceGroupName exampleRG
When no longer needed, use the Azure portal, Azure CLI, or Azure PowerShell to delete the resource group and its resources.
az group delete --name exampleRG
Remove-AzResourceGroup -Name exampleRG
For a step-by-step tutorial that guides you through the process of creating a Bicep file with Visual Studio Code, see:
[!div class="nextstepaction"] Quickstart: Create Bicep files with Visual Studio Code
For other ways to deploy a SQL Server VM, see:
To learn more, see an overview of SQL Server on Azure VMs.