Experiments with Azure DevTest Labs

I've had an Azure credit burning a hole in my pocket for a while so I've been playing with a few options for using it up. One thing I would like is an automated lab build for testing out various tools. Since I am A Very Busy Person, I decided to take a stab at automating the process. Which took much longer than just building the lab manually would have, but where's the fun in that?

For Very Busy People like me, the kind folks at Microsoft have built a pretty neat tool for getting this done called DevTest Labs. I'm still plumbing these depths, but it looks to be a batteries-included way of rolling out a lab in the cloud. These notes are pretty rough right now but I wanted to get them down and published before I forgot and/or lost interest.

As you'd expect with something including batteries, there are all sorts of built-in templates (called Artifacts) that will install software, build a domain, join systems to a domain, and so on. Handy.

Installing AzureRM

Doing things through Azure's GUI is slow so we're going to use PowerShell. I'm going to assume you're running Windows 10.

First up, install the AzureRM module:

1
Install-Module AzureRM -AllowClobber

Git

I store my system configurations in a Git repository in case I break things and also because things in Git make me happy.

Here's how I have it laid out:

1
2
3
4
5
6
7
8
azure-devtest-builds
├── 2016_domain_controller
|   └── domain_controller_arm.json
|   └── domain_controller_params.json
...
└── w10_workstation
    └── w10_workstation_arm.json
    └── w10_workstation_params.json

The *_arm.json files contain specifications for the VM itself. The *_params.json file contains parameters to be used when building, such as system properties and any information required for various Artifacts.

Create Azure DevTest Lab Using PowerShell

The DevTest Lab is what contains all your VMs. If you're familiar with Azure, you can think of it as a simple way of creating all the supporting infrastructure for a VM (resource groups, network security groups, etc.)

Let's build one with PowerShell. To support the parameters in this template, you'll need to create a parameter file:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
     "name": {
         "value": "<TestLabName>"
     },
     "regionId": {
         "value": "<regionID>"
     }
  }
}

Next you'll need the Azure Resource Manager Template to actually create your DevTest Lab:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
{
    "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "name": {
            "type": "string",
            "defaultValue": ""
        },
        "regionId": {
            "type": "string",
            "defaultValue": ""
        }
    },
    "resources": [
        {
            "apiVersion": "2017-04-26-preview",
            "name": "[parameters('name')]",
            "type": "Microsoft.DevTestLab/labs",
            "location": "[parameters('regionId')]",
            "tags": {},
            "properties": {
                "labStorageType": "Premium"
            },
            "resources": [
                {
                    "apiVersion": "2017-04-26-preview",
                    "name": "LabVmsShutdown",
                    "location": "[parameters('regionId')]",
                    "type": "schedules",
                    "dependsOn": [
                        "[resourceId('Microsoft.DevTestLab/labs', parameters('name'))]"
                    ],
                    "properties": {
                        "status": "Disabled",
                        "timeZoneId": "Mountain Standard Time",
                        "dailyRecurrence": {
                            "time": "1900"
                        },
                        "taskType": "LabVmsShutdownTask",
                        "notificationSettings": {
                            "status": "Disabled",
                            "timeInMinutes": 30
                        }
                    }
                },
                {
                    "apiVersion": "2017-04-26-preview",
                    "name": "[concat('Dtl', parameters('name'))]",
                    "type": "virtualNetworks",
                    "location": "[parameters('regionId')]",
                    "dependsOn": [
                        "[resourceId('Microsoft.DevTestLab/labs', parameters('name'))]"
                    ]
                }
            ]
        }
    ]
}

Finally we can deploy:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Login to Azure
Login-AzureRmAccount

# Display Available Subscriptions
Get-AzureRmSubscription

# Select Subscription
Select-AzureRmSubscription -SubscriptionName <YourSubscriptionName>

# Create Resource Group and Deploy DevTest Lab Template
New-AzureRmResourceGroup -Name <ResourceGroup> -Location "East US"
New-AzureRmResourceGroupDeployment -Name <DeployMentName> -ResourceGroup ARRGName -TemplateFile <TemplateFile> -TemplateParameterFile <TemplateParameterFile>

Create Azure DevTest Lab Using the GUI

Here's how to create your DevTest Lab with more mouse action. This is also handy if you're looking for an easy way to generate resource manager templates.

  1. Log on to Azure
  2. Search for 'DevTest Labs'
  3. Click 'Add'
  4. Fill in the appropriate details
  5. Click Create

Note the name of the Resource Group that gets created as you'll need it for VM deploys.

Create VMs

Back to PowerShell

1
2
3
4
5
# Find your DevTest Lab's Resource Group
Get-AzureRmResourceGroup

# Roll out your template
New-AzureRmResourceGroupDeployment -Name <DeploymentName> -ResourceGroup <ResourceGroupName> -TemplateFile <TemplateFile>

References

<<
>>