Edit

Share via


Quickstart: Use Bicep to create a lab in DevTest Labs

This quickstart uses Bicep to create a lab in Azure DevTest Labs that has one Windows Server 2019 Datacenter virtual machine (VM) in it.

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.

In this quickstart, you:

  • Review the Bicep file.
  • Deploy the Bicep file to create a lab and VM.
  • Verify the deployment.
  • Clean up resources.

Prerequisites

  • An Azure subscription where you have permissions to create and manage resources. If you don't have one, create a free account.

Review the Bicep file

Review the Bicep file. The file uses the following resource types to take the following actions:

@description('The name of the new lab instance to be created')
param labName string

@description('Location for all resources.')
param location string = resourceGroup().location

@description('The name of the vm to be created.')
param vmName string

@description('The size of the vm to be created.')
param vmSize string = 'Standard_D4_v3'

@description('The username for the local account that will be created on the new vm.')
param userName string

@description('The password for the local account that will be created on the new vm.')
@secure()
param password string

var labSubnetName = '${labVirtualNetworkName}Subnet'
var labVirtualNetworkId = labVirtualNetwork.id
var labVirtualNetworkName = 'Dtl${labName}'

resource lab 'Microsoft.DevTestLab/labs@2018-09-15' = {
  name: labName
  location: location
}

resource labVirtualNetwork 'Microsoft.DevTestLab/labs/virtualnetworks@2018-09-15' = {
  parent: lab
  name: labVirtualNetworkName
}

resource labVirtualMachine 'Microsoft.DevTestLab/labs/virtualmachines@2018-09-15' = {
  parent: lab
  name: vmName
  location: location
  properties: {
    userName: userName
    password: password
    labVirtualNetworkId: labVirtualNetworkId
    labSubnetName: labSubnetName
    size: vmSize
    allowClaim: false
    galleryImageReference: {
      offer: 'WindowsServer'
      publisher: 'MicrosoftWindowsServer'
      sku: '2019-Datacenter'
      osType: 'Windows'
      version: 'latest'
    }
  }
}

output labId string = lab.id

Deploy the Bicep file

  1. Save the Bicep file as main.bicep to your local computer.

  2. Run the following commands using either Azure CLI or Azure PowerShell from the folder where you saved the Bicep file. In the commands, replace the following placeholders:

    • <location>: Azure region you want to use.
    • <lab-name>: Name for the new lab.
    • <vm-name>: Name for the new VM.
    • <user-name>: Username of a local account to create on the new VM. You're prompted to enter a password for the local account. Be sure not to use any disallowed usernames or passwords listed in the OSProfile section of Virtual Machines - Create or Update.
    az group create --name exampleRG --location <location>
    az deployment group create --resource-group exampleRG --template-file main.bicep --parameters labName=<lab-name> vmName=<vm-name> userName=<user-name>
    

The deployment also creates a resource group for the VM named <lab-name>-<vm-name>-<numerical-string>. This resource group contains VM resources like the IP address, network interface, and disk.

When the deployment completes, the output shows data about the resources and the deployment.

Validate the deployment

Use Azure CLI or Azure PowerShell to list the deployed resources in the resource group. You can also use the Azure portal.

az resource list --resource-group exampleRG

Clean up resources

You can use Azure CLI or Azure PowerShell to delete the resource group and all of its resources when you don't need them anymore. You can also use the Azure portal.

If you want to manually delete the lab's resource group, you must delete the lab first. You can't delete a resource group that has a lab in it.

az group delete --name exampleRG

Next step

To connect to lab VMs, see the next tutorial.