-
Article -
05/13/2022 - 4 minute read
-
Is this page useful?
Feedback will be sent to Microsoft: By pressing the send button, your feedback will be used to improve Microsoft products and services. Privacy Policy.
Merci.
<!– –>
This quickstart guide shows you how to create a Data Science Virtual Machine Ubuntu 18.04 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 consistency, and support for code reuse. Bicep provides 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.
Examine the Bicep File
The Bicep file used in this quickstart is taken from the 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)
}
}
dependsOn: [
storageAccount
]
}
output adminUsername string = adminUsername
The following resources are defined in the Bicep file:
Deploy Bicep File
-
Save the Bicep file as main.bicep on your local computer.
-
Deploy the Bicep file using 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>
New-AzResourceGroup -Name exampleRG -Location eastus New-AzResourceGroupDeployment -ResourceGroupName exampleRG -TemplateFile ./main.bicep -adminUsername "<admin-user>" -vmName "<vm-name>"
Notes
Replace by the username of the administrator account. Replace by the name of your virtual machine.
When the deployment is complete, a message should appear indicating that the deployment was successful.
Check deployed resources
Use the Azure portal, Azure CLI, or Azure PowerShell to list the resources deployed in the resource group.
az resource list --resource-group exampleRG
Get-AzResource -ResourceGroupName exampleRG
Clean up resources
When you no longer need the resource group or its resources, use the Azure portal, Azure CLI, or Azure PowerShell to delete them.
az group delete --name exampleRG
Remove-AzResourceGroup -Name exampleRG
Following steps
In this quickstart, you created a Data Science Virtual Machine using Bicep.