Quickstart: Create an Ubuntu Data Science Virtual Machine using Bicep
This quickstart will show you how to create an Ubuntu Data Science Virtual Machine using Bicep. Data Science Virtual Machines are cloud-based virtual machines preloaded with a suite of data science and machine learning frameworks and tools. When deployed on GPU-powered compute resources, all tools and libraries are configured to use the GPU.
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.
Prerequisites
An Azure subscription. If you don't have an Azure subscription, create a free account before you begin.
Review the Bicep file
The Bicep file used in this quickstart is from Azure Quickstart Templates.
@description('Username for Administrator Account')
param adminUsername string
@description('The name of you Virtual Machine.')
param vmName string = 'vmName'
@description('Location for all resources.')
param location string = resourceGroup().location
@description('Choose between CPU or GPU processing')
@allowed([
'CPU-4GB'
'CPU-7GB'
'CPU-8GB'
'CPU-14GB'
'CPU-16GB'
'GPU-56GB'
])
param cpu_gpu string = 'CPU-4GB'
@description('Name of the VNET')
param virtualNetworkName string = 'vNet'
@description('Name of the subnet in the virtual network')
param subnetName string = 'subnet'
@description('Name of the Network Security Group')
param networkSecurityGroupName string = 'SecGroupNet'
@description('Type of authentication to use on the Virtual Machine. SSH key is recommended.')
@allowed([
'sshPublicKey'
'password'
])
param authenticationType string = 'sshPublicKey'
@description('SSH Key or password for the Virtual Machine. SSH key is recommended.')
@secure()
param adminPasswordOrKey string
var networkInterfaceName = '${vmName}NetInt'
var virtualMachineName = vmName
var publicIpAddressName = '${vmName}PublicIP'
var subnetRef = resourceId('Microsoft.Network/virtualNetworks/subnets', virtualNetworkName, subnetName)
var nsgId = networkSecurityGroup.id
var osDiskType = 'StandardSSD_LRS'
var storageAccountName = 'storage${uniqueString(resourceGroup().id)}'
var storageAccountType = 'Standard_LRS'
var storageAccountKind = 'Storage'
var vmSize = {
'CPU-4GB': 'Standard_B2s'
'CPU-7GB': 'Standard_D2s_v3'
'CPU-8GB': 'Standard_D2s_v3'
'CPU-14GB': 'Standard_D4s_v3'
'CPU-16GB': 'Standard_D4s_v3'
'GPU-56GB': 'Standard_NC6_Promo'
}
var linuxConfiguration = {
disablePasswordAuthentication: true
ssh: {
publicKeys: [
{
path: '/home/${adminUsername}/.ssh/authorized_keys'
keyData: adminPasswordOrKey
}
]
}
}
resource networkInterface 'Microsoft.Network/networkInterfaces@2021-05-01' = {
name: networkInterfaceName
location: location
properties: {
ipConfigurations: [
{
name: 'ipconfig1'
properties: {
subnet: {
id: subnetRef
}
privateIPAllocationMethod: 'Dynamic'
publicIPAddress: {
id: publicIpAddress.id
}
}
}
]
networkSecurityGroup: {
id: nsgId
}
}
dependsOn: [
virtualNetwork
]
}
resource networkSecurityGroup 'Microsoft.Network/networkSecurityGroups@2021-05-01' = {
name: networkSecurityGroupName
location: location
properties: {
securityRules: [
{
name: 'JupyterHub'
properties: {
priority: 1010
protocol: 'Tcp'
access: 'Allow'
direction: 'Inbound'
sourceAddressPrefix: '*'
sourcePortRange: '*'
destinationAddressPrefix: '*'
destinationPortRange: '8000'
}
}
{
name: 'RStudioServer'
properties: {
priority: 1020
protocol: 'Tcp'
access: 'Allow'
direction: 'Inbound'
sourceAddressPrefix: '*'
sourcePortRange: '*'
destinationAddressPrefix: '*'
destinationPortRange: '8787'
}
}
{
name: 'SSH'
properties: {
priority: 1030
protocol: 'Tcp'
access: 'Allow'
direction: 'Inbound'
sourceAddressPrefix: '*'
sourcePortRange: '*'
destinationAddressPrefix: '*'
destinationPortRange: '22'
}
}
]
}
}
resource virtualNetwork 'Microsoft.Network/virtualNetworks@2021-05-01' = {
name: virtualNetworkName
location: location
properties: {
addressSpace: {
addressPrefixes: [
'10.0.0.0/24'
]
}
subnets: [
{
name: subnetName
properties: {
addressPrefix: '10.0.0.0/24'
privateEndpointNetworkPolicies: 'Enabled'
privateLinkServiceNetworkPolicies: 'Enabled'
}
}
]
}
}
resource publicIpAddress 'Microsoft.Network/publicIPAddresses@2021-05-01' = {
name: publicIpAddressName
location: location
sku: {
name: 'Basic'
tier: 'Regional'
}
properties: {
publicIPAllocationMethod: 'Dynamic'
}
}
resource storageAccount 'Microsoft.Storage/storageAccounts@2021-08-01' = {
name: storageAccountName
location: location
sku: {
name: storageAccountType
}
kind: storageAccountKind
}
resource virtualMachine 'Microsoft.Compute/virtualMachines@2021-11-01' = {
name: '${virtualMachineName}-${cpu_gpu}'
location: location
properties: {
hardwareProfile: {
vmSize: vmSize[cpu_gpu]
}
storageProfile: {
osDisk: {
createOption: 'FromImage'
managedDisk: {
storageAccountType: osDiskType
}
}
imageReference: {
publisher: 'microsoft-dsvm'
offer: 'ubuntu-1804'
sku: '1804-gen2'
version: 'latest'
}
}
networkProfile: {
networkInterfaces: [
{
id: networkInterface.id
}
]
}
osProfile: {
computerName: virtualMachineName
adminUsername: adminUsername
adminPassword: adminPasswordOrKey
linuxConfiguration: ((authenticationType == 'password') ? json('null') : linuxConfiguration)
}
}
}
output adminUsername string = adminUsername
The following resources are defined in the Bicep file:
- Microsoft.Network/networkInterfaces
- Microsoft.Network/networkSecurityGroups
- Microsoft.Network/virtualNetworks
- Microsoft.Network/publicIPAddresses
- Microsoft.Storage/storageAccounts
- Microsoft.Compute/virtualMachines: Create a cloud-based virtual machine. In this template, the virtual machine is configured as a Data Science Virtual Machine running Ubuntu.
Deploy the Bicep file
Save the Bicep file as main.bicep to your local computer.
Deploy the Bicep file using either Azure CLI or Azure PowerShell.
az group create --name exampleRG --location eastus az deployment group create --resource-group exampleRG --template-file main.bicep --parameters adminUsername=<admin-user> vmName=<vm-name>
Note
Replace <admin-user> with the username for the administrator account. Replace <vm-name> with the name of your virtual machine.
When the deployment finishes, you should see a message indicating the deployment succeeded.
Review deployed resources
Use the Azure portal, Azure CLI, or Azure PowerShell to list the deployed resources in the resource group.
az resource list --resource-group exampleRG
Clean up resources
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
Next steps
In this quickstart, you created a Data Science Virtual Machine using Bicep.
Feedback
Submit and view feedback for