Creating an Azure virtual machine template from scratch can be a daunting task. In this video, learn how to create an Azure virtual machine template while provisioning a new virtual machine.
- [Instructor] When you get started with templates, it's easiest to work with existing templates and you can get existing templates from a variety of locations. You can use one on the Azure Quickstart Templates, it's already provided for you. You can download the template from GitHub. You can create a template before you provision a resource. For example, I've already configured the virtual machine, but I haven't created it as of yet. I can go ahead and download the template. We can also create templates from existing resources, and that's what I'm going to do here. We're going to create a template from an existing Azure Virtual Machine. We created this virtual machine earlier in this course. Under Settings, select Export template and now we can grab a snapshot of this machine in its current state. Before we do that, let's quickly review the template itself. As we can see, we have our schema, our contentVersion, our parameters, and there are four of them. We have the virtual machine, the two disks and the network interface. I can also tell there's four by selecting Parameters here, and I can see those four parameters. If I had any variables, they would be listed. And we only have one resource and this is for Microsoft.Compute/virtualMachines. I can download these files as JSON templates. I can add them to the library or I can actually deploy them right from here. For this demonstration, we're going to add them to the library. Provide a name and description, and then you can save. You'll notice that you're not popped over into the template blade. In order to do that, you'll have to actually navigate to it. And here you're going to see that I have several different templates and some of them span back a couple of years at this point, some of them are really simple, like the one we just created, which is a base image, or I have some complex templates, including one that has a VM for DC, and it has two virtual machines for ADFS servers. We have a template that has a frontend and backend deployment. Your template will be as simple or as complex as you need. Let's go ahead and take a look at the one that I just created. We can make simple edits within the portal. For more complex edits, you'll want to use your favorite editing tool, such as Visual Studio Code. I'm going to select the template. And at this point, I could make some simple edits. I could change this from a Standard_DS1_v2 to, let's say, Standard_A1. Select OK, and then save again. I will show you how to deploy templates a little bit later in this chapter. Let's also create a template from a resource group. The process is the same. We'll select Export template, but now you'll notice that our template is quite a bit larger because we've included everything in that resource group. We have 15 different parameters and 23 different resources. The one thing I do want to point out here is, we have two resource types that cannot be exported. Not everything can be exported to a template. You can also export templates using the command line interface, PowerShell and the REST API. Let's pop into PowerShell and we'll export this resource group as a template. To export a resource group using PowerShell is really simple. You'll use Export-AZResourceGroup and provide the resource group name, that's it. I have already downloaded this JSON template previously, therefore I'm being prompted, do I want to overwrite it? Yes, I do. And as before we can see those two errors. You now know how to create templates from existing resources, so you don't have to reinvent the wheel.
- Configuring high availability
- Deploying scale sets
- Creating virtual machines
- Configuring Azure Disk Encryption
- Managing virtual machine sizes
- Provisioning a virtual machine
- Automating VM deployment and configuration with templates
- Creating containers with AKS and ACI
- Creating web apps with Azure App Service