Introduction
Azure Cloud Lab Environment is aims to facilitate educators using Azure in their teaching. Using Azure, educators can create the tailor-made lab environment for every student, and it is very important during the pandemic as students cannot back to school and they do not have a good PC at home. On the other hand, students need to work on some complicate deployment projects to learn Azure across the semester. Two main problems – the First is the project cost to continue running the project for a few months, and the second there is no check point for students. In case, a student done something wrong in middle of semester, then he must redo everything or just give up the project. As a result, it limits the scale of student lab project exercise.
My working group (students) of the department of Information Technology - Hong Kong Institute of Vocational Education (IVE) Lee Wai Lee has built up the Azure Cloud Lab Environment, and widely adopted in the teaching of IT114115 Higher Diploma in Cloud and Data Centre Administration.
The focus of Azure Cloud Lab Environment:
- Fully utilize Azure Services – allow students to rebuild the lab environments under their Azure subscription and continuous lab exercise. And it works for all types of free Azure subscriptions such Azure for Students, Azure Free trial, Azure Education Hub, …
- Cost saving – lab infrastructure creates before lab class starts and destroy after the lab class end.
- Automation – It follows Google Calendar schedule.
- Easy Deploy – Educator can deploy the solution with Terraform, ARM template, Bicep, and Azure cli.
- Serverless – the whole solution is using Azure Function under consumption plan.
- Lab Infrastructure Evolution – All students Azure Infrastructure can keep evolution automatically and let them learn how to build a large-scale real-world project with the lowest cost.
Architecture
The main function of the system is to create and destroy Infrastructure according to class schedule.
CalenderPollingFunction
It runs every 5 minutes and check the Google Calendar for upcoming class. When event starts it sends message to start-event queue and when event ends it sends message to end-event queue. The event message includes the name of the lab, GitHubRepo, Branch, and Repeated Times. Repeated Times is calculated by CompletedEvent table historical record. It keeps OnGoingEvent table up-to-date.
StartEventPoisonEventFunction and EndEventPoisonEventFunction
It sends error details to administrator email and saves the error details to ErrorLog table.
StudentRegistrationFunction
It provides an online registration form for students to submit their Azure Subscription services principal. It prevents the duplication of submission by saving the name of lab and subscription ID in Subscription table, make a call to student subscription to ensure the services principal in Contributor role, and save the student email and services principal data in LabCredential table. Student need to
az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/<Your Subscription ID>"
StartLabEventHandlerFunction and EndLabEventHandlerFunction
They handle the message of start-event queue and end-event queue respectively. They are very similar, and the only difference is the container starting command – deploy.sh and undeploy.sh. they convert the event message into lab object for common parameters such as lab, GitHubRepo, Branch, and Repeated Times. They query the LabCredential table and get the list of students with services principal data. Each student subscription is handled by one Terraform Container, and pass services principal and other data through environment variables. 1 container group holds 10 containers. They record the creating and deleting activities in Deployment table.
TerraformContainer
It installs Azure CLI, Python 3.9, Terraform, and Curl and it can access the following variables
All containers mounts to containershare file share. Each container has it own folder. The deployment files keeps in the folder before the infrastructure deletion. Since deployment tools such as Terraform need to keep files (state file) for un-deployment.
deploy.sh
undeply.sh
TerraformContainerRegistry
It stores the TerraformContainer and it prevents hitting the rate limit of DockerHub.
CallBackFunction
It provides the https endpoint for the TerraformContainer to callback after deployment and undeployment. It updates the Deployment table and email information to students.
The following example is the default output of Terraform without.
If there is a VM, it can return IP address, username, and password to students.
All student subscriptions clean up to save cost.
If LifeCycleHookUrl is not empty, it will send post request with Terraform output json to LifeCycleHookUrl for 4 lift cycle events – CREATING, CREATED, DELETING, and DELETED.
The use case of LifeCycleHookUrl will be demonstrated in Azure Hybrid Cloud Lab Environment project.
Lab Environment Evolution
Create a repeating event according to the class schedule.
There are 2 ways to create a continuous changing Azure Infrastructure.
- Create new branch for each lab class such as Lab0, Lab1, Lab2, …
TerraformContainer checkout the difference branch every lab class.lab.Branch = lab.Branch.Replace("###RepeatedTimes###", lab.RepeatedTimes.ToString());
- Add conditional deployment logic through 2 environment variables REPEAT_TIMES and TF_VAR_REPEAT_TIMES.
Source Code
Azure Cloud Lab Environment
https://github.com/wongcyrus/AzureCloudLabEnvironment
Example AzureCloudLabInfrastructure Repo
https://github.com/wongcyrus/AzureCloudLabInfrastructure
- main branch is a simple demo to create resource group.
- windows11 branch is running a windows11.
- Bastion branch is a SSH Bastion in Azure container instance, and it is used by Azure Hybrid Cloud Lab Environment project.
Conclusions
This project can centralize manage all student subscriptions with IasC way. It helps educators creating lesson specific Azure Resources for each student. This kind of customization is nearly impossible implementing in traditional physical lab environment. For learn Azure, the best way is to let students implement a large-scale project through out a whole semester or academy year. Automatic infrastructure evolution can let students continue working on the same project infrastructure during the lab class with checkpoint at minimal cost. For other IT course, teachers can create a specialized VM for each course with the latest software every class. Also, on top of this project, we have another project Azure Hybrid Cloud Lab Environment to manage student remote access physical lab computer at home.
Project collaborators include, Andy Lum, Jerry Lam, Fong Ho Luen, Jenny Nga, and Wina Yu from the IT114115 Higher Diploma in Cloud and Data Centre Administration.
About the Author
Cyrus Wong is the senior lecturer of Department of Information Technology (IT) of the Hong Kong Institute of Vocational Education (Lee Wa... and he focuses on teaching public Cloud technologies. He is one of the Microsoft Learn for Educators Ambassador.