Overview
Recently I have been using Azure Lab Services to prepare Lab Environments for testing and training scenarios, and also using various tools to help create and customise these environments as I need. Azure Lab Services provides on-demand or scheduled access to virtual machines to support various scenarios. A summary of the key points is below:
-
Provide access to Virtual Machines in a preconfigured Lab without sharing Azure Subscription details.
-
Use custom templates to provision Virtual Machines, and use these repeatedly across Labs.
-
Use scheduling and usage limits to ensure resources are used in a cost effective manner.
-
Provision and scale quickly – without managing underlying infrastructure.
Some of the typical activities or events that would be a great use case for Azure Lab Services are:
-
Classroom Training
-
Events – Trials / Demos etc.
-
Hackathons
-
Hands on Labs
-
Experimentation
-
Development
-
Testing
✅ You can read more about Azure Lab Services here: https://azure.microsoft.com/en-gb/products/lab-services
As well as provisioning Azure Lab Services manually via the Portal, you can also use Terraform to create Lab Services Resources programmatically, see here: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/lab_service_lab. Programmatic creation of Labs is a great way to automate creation and customisation, and provides all of the usual benefits of a DevOps approach, for example; repeatability, reliability, scalability, commonality and more!
In this post I will explore the basic components of Azure Lab Services, and also explore how we can create and customise them further using Terraform.
Setup
Azure Lab Services consists of the following basic elements (the items that need to be in place before we can start using our Labs):
- Lab Plans – These are effectively a set of Resources and Configurations that will apply to our Labs. Within the Lab plan we will specify things like our Lab Plans name, location, Networking configuration, and tags that we require.
- Labs – These are the actual Labs that we will create for people to access. Within the Labs (created by visiting labs.azure.com) we setup the VM type, OS, Username/Password, and Power Management aspects for the Virtual Machines.
Lab Plans
Setting up a Lab Plan is easy – and requires very little input. To setup a Lab Plan, follow the Steps outlined below. To start, search for “Azure Lab Services”, click on “Lab plans” and then on “Create”:
We can then run through creating the Lab plan. There’s not much we need to specify here other than the usual naming, location, and Resource Group elements:
On the next screen we can enable Advanced Networking – this allows us to place our Lab VMs into a VNET of our choosing, which will then allow the Lab VMs to access resources via that VNET. For example – we may have other Azure Resources required as part of the Lab, so this setting will allow network access to those if required.
For my test, I don’t require advanced networking, so I will leave this unchecked. Next we can move onto Tags and then create the Lab Plan:
Once the Tags and Validation are completed, we can then create our Lab Plan!
Once created – we have access to a range of additional settings within the Lab Plan:
Within the Lab Configuration block (highlighted above), we have access to the following additional settings:
- Lab Settings – Here we can define the Shut down on idle, Shut down on disconnect, Shut down when users do not connect, and Enabled regions for our Lab plan.
- LMS Settings – This provides integrations into Canvas, you can read more on this here: https://learn.microsoft.com/en-gb/azure/lab-services/how-to-configure-canvas-for-lab-plans.
- Marketplace images – This allows us to configure the images that will be enabled under this Lab Plan.
- Azure compute gallery – This allows us to integrate the Lab plan with an Azure Compute Gallery whereby customised images can be used within Azure Lab Services.
- Internal Support – This allows us to set Supports details like Support URL, Support Email, Support Phone, and Support Instructions (so that those using Labs have information and contact details for Support).
✅ Once our Lab Plan is setup – we can move on to creating a Lab!
Labs
Creating labs is done by visiting https://labs.azure.com, once the Lab Plan has been setup. A Lab Plan is required before we can create any labs. This means that Azure Administrators can setup Lab Plans, and then allow Lab Administrators (Teachers, Educators, etc.) to create Labs to suit their needs, using these plans.
Once you have browsed to labs.azure.com you will see a window like this:
Clicking on “Create lab” (highlighted above), will open the following pane. You’ll need to fill in the highlighted area, selecting a Lab Name, Virtual Machine Image, Virtual Machine Size, and Location :
For my Lab, I will be using a Marketplace Windows 11 Image:
Next we need to define the Username and Password for the Lab Virtual Machines – we can also opt for a non-administrative account or to force a new password to be selected upon first logon:
Next up we setup the Lab policies:
Finally, we select whether we need to customise the VM during Lab Creation. For simplicity, I’m just keeping the image as it is:
Once this has been selected, our Lab will then be created:
Once the Lab has been created, we can then customise the Virtual Machine and our Lab further:
Once we have finished updating the VM Title and Description, we can then publish this VM:
When we click “Publish” we are given an option to choose the required number of VMs:
The VM is then published, which can take up to 20 minutes:
Whilst the VMs are being created (I opted to create 2 VMs for this Blog post), we can see these being created in the “Virtual machine pool” section:
Once the VMs have been created, the status will show as published, and the VMs no longer show as creating:
Next – we can update various settings within the Lab. Note: this can also be done whilst you are waiting for the VMs to be created! Firstly, I will setup the Automatic Shutdown and disconnect options, as this will save some Azure spend:
We can also define a Schedule for our lab. This will ensure our lab is started/stopped at the required times (which could be setup to align to Class/Lesson/Event times, for example):
Finally, we need to add some users to our Lab – so that they can access the Resources within the Lab. This is done from the “Users” pane:
I’ve added a single user manually, however you can sync users from an Azure AD group here too. Once users are added, you can invite via email or copy the registration link:
I’ve opted to invite via email – which allows you to send a custom message too. Users will then receive an email like the one below:
When users Click on the “Register for the lab” link, they are presented with the following screen, which shows the VMs available to them. Because we do not have a schedule in place, the VM will need to be started:
Once clicked, the VM starts up:
Once started, we can access the VM by clicking on the PC symbol, which will provide us with an RDP file:
Once we have downloaded the RDP file and authenticated using the previously setup credentials, we are logged into our VM:
Using Terraform
Using Terraform we can create the core components of Azure Lab Services, as well as providing additional levels of customisation and control. I’ve broken these down into the individual components below, and provided a full Lab you can deploy within my GitHub Account here. If you are new to Azure Lab Services I would recommend starting with the Portal first and then moving onto Terraform.
Lab Service Plans
You can create these using the azurerm_lab_service_plan Resource within the AzureRM provider. Here’s an example of this from my Lab below:
# Lab Service Plan resource "azurerm_lab_service_plan" "plan1" { name = "lsp-${var.labname}-${var.region}" resource_group_name = azurerm_resource_group.rg.name location = var.region allowed_regions = [var.region] support { email = "jake@jakewalsh.co.uk" instructions = "Welcome to your Azure Lab, please raise a support request if you encounter any issues" url = "https://jakewalsh.co.uk" } tags = { Environment = var.labname Function = "AzureLabServices" } }
Labs
Labs can be created using azurerm_lab_service_lab Resource within the AzureRM provider. In my lab, I started using the below example:
# Lab resource "azurerm_lab_service_lab" "lab1" { name = "lab-${var.labname}-${var.region}" resource_group_name = azurerm_resource_group.rg.name location = var.region title = "Lab 1" description = "Virtual Machine for Lab Environment" lab_plan_id = azurerm_lab_service_plan.plan1.id connection_setting { client_rdp_access = "Public" } security { open_access_enabled = false } virtual_machine { shared_password_enabled = true admin_user { username = "labadmin" password = "Password12345!!" } image_reference { offer = "windows-11" publisher = "MicrosoftWindowsDesktop" sku = "win11-21h2-pro" version = "latest" } sku { name = "Classic_Fsv2_8_16GB_128_S_SSD" capacity = 1 } } tags = { Environment = var.labname Function = "AzureLabServices" } }
Also worth noting – if you wish to use shared passwords (the same password for all VMs) you need to specify shared_password_enabled = true, and for Public RDP access client_rdp_access needs setting to “Public”. Both of these are set in the above example and my GitHub repo.
⚠ Note: The above example has the password in plain text within the TF files, which is less than ideal, so you can use Azure Key Vault to manage the Lab Passwords. See the example below using a Password value from a Key Vault. The full example within my GitHub repo creates the Key Vault and a random password value and uses this within the Lab, as well as using a variable for the admin username. (Example below):
admin_user { username = var.labusername password = azurerm_key_vault_secret.vmpassword.value }
Lab Schedules
Lab Schedules can also be created using Terraform – by using the azurerm_lab_service_schedule object. I have not included this in my example as I wanted the machines booted on-demand, however, you can use the example schedule below to power up/down VMs as required:
resource "azurerm_lab_service_schedule" "schedule1" { name = "schedule-${var.labname}-${var.region}" lab_id = azurerm_lab_service_lab.lab1.id stop_time = "2023-03-22T00:00:00Z" time_zone = "Europe/London" }
Lab Users
Lab Users (the users who will access the Lab VMs), can also be added using Terraform – by using the azurerm_lab_service_user object. If, for example for each Lab you wanted to add a specific user, perhaps for testing, you could add this here:
resource "azurerm_lab_service_user" "user1" { name = "User" lab_id = azurerm_lab_service_lab.lab1.id email = "user@jakewalsh.co.uk" }
Customising Images
Within the Lab Plan, we also have the option of utilising an Azure Compute Gallery, which allows the upload of VM images and sharing with Labs in the plan. Creating this from the Portal is straightforward, and if required, you can also attach an existing Compute Gallery:
The name of the Gallery is automatically generated for us:
Once created, we now have a Gallery we can save images into:
Conclusion and Further Reading
As you can see, Azure Lab Services provides an easy to use, and customisable solution for Lab environments within Azure. As well as providing a framework to create labs, there are options to create and utilise custom images, as well as a range of options to create these environments programmatically, with tools like Terraform.
If you are interested in learning more about Azure Lab Services, check out the following links:
- https://azure.microsoft.com/en-gb/products/lab-services
- https://learn.microsoft.com/en-gb/azure/lab-services/
- https://learn.microsoft.com/en-gb/azure/lab-services/tutorial-setup-lab
- https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/lab_service_lab
Thanks for reading! ✅