Setup Identical Environments Across Multiple Virtual Machines To Host Hackathons And Training

Introduction

This is a follow-up article of “Create Virtual Environments with Azure Lab Services” If you are new to Azure Lab Services then it would be better to read it first. Moreover, this article is also part of the Azure Advent Calendar where experts from different communities share their knowledge through their own contributions in different formats, the most common being publications in their blogs, although they can also be videos, webinars, etc. Read more about it.

In this step-by-step tutorial, I will demonstrate how to create a virtual environment using Azure Lab Services to host an enterprise hackathon, reducing the time and effort of people to set up multiple virtual machines with the software developers probably need to innovate and solve the challenges of the hackathon. This tutorial covers the following topics.

  • How to create lab plans
  • How to grant access to a lab plan
  • How to create a lab
  • How to customize the template virtual machine
  • How to publish the template virtual machine
  • How to add users to the lab
  • How to schedule events
  • How to use a pre-configured VM

Hands-on experience

Let us suppose the enterprise Contoso develops APIs for its customers. Recently, they realized that some of their APIs could be migrated to serverless workloads to save costs. A Program Manager has suggested hosting a serverless hackathon to enhance the skills and knowledge of the developer teams. However, the developer teams cannot stop their daily activities to install and set up an environment to develop serverless functions and neither can the manager install the software in multiple virtual machines for every team. Someone has suggested using Azure Lab Services to prepare the environments and host a one-day hackathon. As the company is using .NET, most likely all virtual machines will require either Visual Studio or VSCode with some extensions and packages to develop serverless functions with the C# SDK.

Throughout the example, the terms “Educator” and “Student” continue to appear to refer to the roles explained in the previous article. In this example, the Educator could be the Program Manager and the Student could be a developer team.

Pre-requisites

To use Azure Lab Services you will need an Azure Subscription, you can get one here, or if you are a student you can create one with Azure for students.

Step 1: Create a lab plan

For this article, Azure Portal is used along all steps, but Azure CLI could be used instead.

Create a resource group with a name (see suggested pattern) and a region close to your users. Then, search for “azure lab services” in the marketplace and choose Lab plan. Click on Create and fill the Basics section (shown in Figure 2) from the wizard with a lab plan name (see suggested pattern) and a region (ideally the same region as your resource group).

Azure Lab Services in Azure Marketplace

Figure 1

Create a lab plan following the wizard. Select or create a new resource group where the lab plan will be created. Choose a name and location.

Figure 2

If you do not plan to connect your new virtual machines to other existing virtual machines from your network, skip advanced networking options. Later, you can add a tag if you want (it is always a good idea to do so). Finally, Click on Review + Create and wait for the deployment to be completed.

Click on Go to resource and you will see some options to configure your labs.

Default screen (Overview) of the lab plan where you have multiple options. 1. Creating labs 2. Lab settings 3. Azure Compute Gallery 4. Internal Support Information 5. Lab creators

Figure 3

Step 2: Grant access

Click on Add lab creators (Figure 3) to assign Role-Based Access Control (RBAC) to the Educator.

In this article, the Educator is added to the Lab Creator role (Figure 4), if you need granular control check this out for a detailed description of the roles.

Add role assignment wizard First, select a role. Second, assign a either user, group, service principal or managed identity. Third, add memberds Fourth (optional) add a description

Figure 4

After you review and assign the role, this one will appear in the IAM panel (Figure 5)

In Identity and Access Management you will notice the educator has the role you just assigned to.

Figure 5

Then, you (the Owner) and the Educator can create labs. Go back to the overview section and click on Create a lab (Figure 3).

Step 3: Create a lab

Create a lab in labs.azure.com.

Figure 6

First, you will need a lab name (this is not the lab plan name) as you can have multiple labs in a single lab plan. Second, an image of the operating system (OS) (Linux or Windows), you will notice there is only a limited list in the dropdown menu, however, you can enable more from the marketplace images (Figure 7) and also use Azure Compute Gallery. Take a look at Figure 7, there is even an existing image with Visual Studio installed, that is already a part of the tasks we wanted to do. Third and fourth, choose size and location (depending on your selection costs may vary)

Marketplace images where you have multiple options between popular Linux and Windows images. Sych as Ubuntu or Windows Server.

Figure 7

Click next and create a user for your template VM. You can create a non-admin account for the VMs, and you can opt to use that same password for all VMs or ask the user to create one immediately at his/her first login.

Virtual machine credentials. Must include 3 of the following: a number, uppercase character, lower character, and a special character

Figure 8

In step 3, you can set the number of hours that users can use their virtual machines outside of a scheduled event. This option could be useful for students who need some time to do the homework outside of class time. For a hackathon, this may not be necessary but let us give 2 hours so that the developers could save their solutions after the hackathon is finished. In the same step, you have some options to shut down the VMs automatically after user inactivity, after users have logged out or when a user did not log in.

Lab policies. Can always be changed after the labs is created.

Figure 9

In the last step, Azure Lab Services asks if you need to customize something else, if that is the case, then it will provide you a template VM where you can install everything you need. If that was not the case and you are ready to go with the selected OS image the process will be shorter as you will not customize the template VM. For this article, let us suppose Visual Studio was not enough for the hackathon and the Educator needs to add additional software. Keep the first option selected (Figure 10)

Create a template virtual machine or not. It enables you to customize the content of the virtual machines in the lab (by installing additional software, adjusting settings, or adding files). This will add 5-15 minutes to the lab creation time.

Figure 10

Once completed you will be able to connect to your template VM over Remote Desktop Protocol (RDP)

Initially, the VM will be stopped (Figure 11), you manage the template and the replicates directly from the Azure Lab Services Portal, not the Azure Portal. Notice at the top (Figure 11) there is a button to publish. This one will be selected when the Educator decides the VM has everything installed and is ready to be used by the Students.

template VM initially stopped.

Figure 11

Start the VM and connect as you would do with other VMs, log in with the username and password you have previously created, and you are ready to go.

template vm options after starting it.

Figure 12

Step 4: Customize the template VM

Welcome message after log in with RDP

Figure 13

You will notice Visual Studio is already installed as shown in Figure 14. In fact, VSCode is installed too with this OS image (it simply does not appear as a shortcut on the desktop). So, having both Visual Studio and VSCode gives our developer teams the freedom to choose between the two.

Template VM desktop with Visual Studio and Unity installed

Figure 14

Visual Studio seems to be ready for the hackathon. Since the Azure Function template works fine.

Visual Studio with the Azure Function template which is a Http Trigger with a query parameter called name

Figure 15

However, VSCode requires some prerequisites and requirements to develop functions in VSCode. VSCode already provides multiple ways to sync your extensions. However, there is a couple of steps besides extensions. So, having everything installed in the template can be handy for the developers so that they can start right away.

VSCode warning about Azure Functions Core Tools

Figure 16

After installation of Azure Function Core Tools and after reboot, VSCode is ready to be used for azure functions development.

VSCode with the Azure Function template which is a Http Trigger with a query parameter called name

Figure 17

Additionally, VSCode was added to the desktop as well as a txt file with the hackathon rules. We could have hidden the Unity and the Survey that came from the OS Image but this does not matter.

Template VM desktop with the finished set up, showing Visual Studio, VSCode and the rules in a txt.

Figure 18

Step 5: Publish the template

Once you have finished customizing the VM, it will be stopped to be published. Let us say there are 5 teams and each of them will use a VM. Another option would be to create one VM for each developer of each team, but this could increase the number of VMs considerably.

wizard to publish the template VM

Figure 19

Once you have published them, the 5 VMs will be visible in the Virtual Machine pool (Figure 20).

virtual machine pool section where all VMs are displayed with their info

Figure 20

You can access each of them individually if you want, however, ideally you will assign each of them to a user. Therefore, go to Users and add them manually or with Azure AD Groups.

Step 6: Add users

For Azure AD Group, go to Azure Portal, search for Azure Active Directory, and then New Group

Azure AD Groups in Azure Portal

Figure 21

Give it a name, and description. The most important part is where you add the members.

Add members to a Azure AD Group

Figure 22

Then sync it with Azure Lab Services

The created Azure AD Group displayed in Azure Lab Services dropdown menu to sync users.

Figure 23

However, notice that the lab will be permanently synced from the group. Once synced, you will not be able to manually add or remove users and machines in this lab at any time.

The second option would be to add them manually or with a CSV

import users by email or upload them with a CSV

Figure 24

Once you have added them you must invite them by email or share a registration link. You can also customize a message in the email and include the link to join.

invite button to send an email with the registration link and a message

Figure 25

The email looks like Figure 26

example email received after invitation

Figure 26

Once the user has accepted the invitation, the Status will change in the portal

Status has changed to registered

Figure 27

A list of the VMs to which he/she has access is displayed in Figure 28. For example, this user had already access to another VM from a lab called Lab-de-prueba and he/she has used some time outside of what is scheduled.

available VMs to user after registration

Figure 28

Step 7: Schedule an event

Now you can schedule the hackathon so that the users do not spend the allowed time outside of events (i.e., 2 hours for this example)

add scheduled event

Figure 29

scheduled event in calendar

Figure 30

The hackathon was scheduled from 2:30 – 7:30 am (UTC+2) so during this period users can use the VMs without spending their additional time.

Go back to the VM pool, you will notice a VM was assigned to a user when he/she has accepted the invitation through his/her email.

virtual machine pool with the first VM assigned to the new user

Figure 31

The Educator can start all VMs but for that particular VM, both the Student and the Educator can start it.

There is also a dashboard where you have information about the lab. If you need to make changes to the template VM you need to republish it, but all VMs will be replaced again.

dashboard from the azure lab services portal (template info, virtual machine pool info, users info and schedules)

Figure 32

Step 8: Start the VM as the Student

desktop from the user, which contains exactly the software and tools installed in the template VM

Figure 33

That is it! You have everything you need to start developing solutions for the hackathon as all the tools that were installed in the template VM are already there in each VM. Now, these VMs are different from each other. Thereby, each team has its own development environment.

Summary

In this article, I discussed how Azure Lab Services allows one to create, manage, provide, and destroy virtual environments. Although this case involved setting up VMs for an enterprise hackathon, there are a variety of scenarios as discussed in the previous article. Azure Lab Services can be deployed by an IT Administrator who will provide access to the lab plan to the Educator. In a plan, there may be multiple labs, and each of them could have or not have a template VM with a base OS image from the marketplace or yours. The template VM must be published once completed and select how many VMs will be deployed. Then, you can sync an Azure AD Group with the users and import them manually or with a CSV. Later, you must send an invitation email or share the registration link with them. Once a VM is assigned to a user, the user could use it during a scheduled event and during the time the user is allowed to use the VM outside of a scheduled event. At the end of this article, we saw that a user was able to use a pre-configured virtual machine with the software that was installed in the template VM, saving time and effort.