The course is part of these learning pathsSee 4 more
Introduction to Azure Resource Manager
Template Deployment & Advanced Concepts
This course will introduce the Microsoft Azure Resource Manager (ARM) REST API, and how to interact with it using the Azure Cross-Platform (xPlat) CLI Tool and the ARM PowerShell module. The ARM interface is a web service that provides two primary mechanisms for managing cloud resources:
- Declarative provisioning using Azure Resource Manager (ARM) JSON Templates
- Imperative provisioning - provisioning or deprovisioning cloud resources one-by-one
Microsoft's ARM interface offers several different methods of accessing it:
- REST API - A REST interface to interact with ARM
- PowerShell Module - The Azure Resource Manager PowerShell module can be installed directly from the PowerShell Gallery, and enables you to manage cloud resources both declaratively and imperatively.
- Cross-Platform (xPlat) CLI Tool - A Node.js-based automation tool that runs across multiple platforms, including Linux, Mac OS X, and Windows. This utility enables declarative and imperative management of cloud resources inside your Microsoft Azure subscription. It even enables certain automation functions within the Azure Active Directory (AAD) identity service.
- Python Module - a Python module that can be easily installed using pip, enabling declarative and imperative management of Azure resources via ARM.
After participating in this course, you'll be enabled with the following information:
- The architecture of the Microsoft Azure Resource Manager (ARM) interface
- installing and getting started with the ARM PowerShell module
- Installing and getting started with the Azure Cross-Platform (xPlat) CLI Tool
- How to build and understand Azure Resource Manager JSON Templates
- Common software tools you'll encounter, surrounding Azure Resource Manager
- Declarative provisioning and imperative provisioning of cloud resources in Azure
If you have thoughts or suggestions for this course, please contact Cloud Academy at email@example.com.
Hello, in this demonstration, we are going to take a look at one of the most popular tools that helps you to build Azure Resource Manager JSON templates. In this case, we are running the Visual Studio Code product on Mac OSX, but you can also run Visual Studio Code on Linux, as well as Windows. In order to author Resource Manager templates, we need to install an extension for Visual Studio Code that's called the Azure Resource Manager Tools. So, if we just search for extension here, we choose install extension, and then we can provide a search term, like azure. And, you'll see that there is an Azure Resource Manager Tools extension, which is version 0.1. If we just hit enter to install that extension, it'll download and install it locally, and then will be prompted to restart Visual Studio Code in order to finish the installation process. So, let's click the restart now button. And, the Visual Studio Code window will reload very quickly, and allow us to get started. Now, we need to change the file format to JSON. So, to do that, we hit F1. We'd search for the Change Language Mode option. And then, we'll search for JSON, and hit enter to confirm that we want the JSON file format. You can also click the button on the bottom right to change the language that you're currently operating in. Before we actually get started authoring the template, we need to build a basic framework for us to work off of. The first thing we need to do, is import the schema. And we can do that by going out to the Quickstart Templates, and pulling in the schema from there. So, we'll just grab one of these existing templates. And, we'll copy the schema and content version. We'll go ahead and just put in a closing curly brace to close off the JSON document. And then, we can go ahead and start building out from here. So, the top level sections are going to be auto-completed for us here. We have the parameters section, which allows us to provide input parameters to the template at run time. We can specify our resources under the resources section. We can define variables, using the variables top level section. And, optionally, we can specify outputs that are emitted to the deployment object, after the JSON template has been deployed. So, let's start by building out some parameters. The first thing that we'll do is build a parameters section, and we'll create a parameter called vmSize. Now, the vmSize parameter will be of type string. And then, we'll provide a metadata property that allows us to specify a description. And, inside that description, we'll just say that this parameter specifies the Virtual Machine size for the VMs contained in this template. Make sure that you use friendly descriptions to help other people understand the specific purpose of that input parameter. We can also specify a default value for the parameter. In this case, we'll just choose Standard A0, which is the smallest VM size in Azure. We can also restrict the allowed values. And, we can add Standard_A0. We'll just add a couple of sizes here. Standard A1. And, Standard_A2. Great, so we've built out a parameter. Next, let's build out the variable section. So, we'll hit Control Space to invoke the IntelliSense. We'll go down to variables, and we'll simply define a new variable. This one we'll call VirtualNetwork. And, the value of that VirtualNetwork variable will be a JSON object. And, we'll give it a name. And, we'll also give it a location. And this is the azure region that it will be deployed into, the VirtualNetwork. Now let's go down to the resources. So, we'll build out the resources section. And we'll actually build a virtual network. Now, when you're declaring a new resource inside of the resources array, it's generally best to help the IntelliSense by specifying the resource type first. So, if you specify the resource type of virtual networks, the IntelliSense can now operate on this specific resource type, and give you recommendations for which properties you should be adding. So, we'll add the API version, which is required for all resources. And, as you can see, we get the nice auto-completion there for it. Next we'll specify the name of the virtual network resource. In this case, we're going to reference the variable, and as you can see, we're getting IntelliSense here for the arm template function, called variables. And, we're gonna grab the VirtualNetwork variable. Unfortunately we don't have IntelliSense for the variable names just yet. And then, we'll reference the name property using dot notation on the variable named VirtualNetwork. So now we've specified the virtual network name, we also need to specify the location to deploy that resource into. So, again we're gonna grab the variable named VirtualNetwork. And, we will reference the location property. We can now use some other properties here, optionally. So, we could specify tags if we want to. We could optionally specify dependencies. We could use the copy property, to make multiple copies of the virtual network, which we're not going to cover in this particularly demonstration. We can also add some comments to help other people understand what the specific virtual network is for. And, finally, we have the required properties. So the properties allow us to actually define all of the details for the virtual network. So, let's go ahead and add an address space. We'll just add 10.5.0.0/16. Next, we'll specify subnets. And, the subnets is going to be an array, because we can have more than one subnet. So we'll go ahead and add a name here. So let's actually go back and fix our address space here, because it's looking for an object. And, so we'll have address prefixes as a child of address space. And then we have an array of address prefixes. So I'll just specify the one here. We could optionally add other address spaces too, like 10.6.0.0/16, and so on and so forth, because this is an array. So, for the subnets here, we'll just come in and specify a subnet with name WebServers. And then, we'll tack on the properties for that subnet. So we're not going to specify a network security group in this case, or a route table, we'll just specify the address prefix, and we'll just make it 10.5.0.0... Meh, how about 5.0/24? Great. So, let's go ahead and add one more subnet. So we'll just hit Control Space. Add the name, DatabaseServers. And then we'll give it a different address prefix. And I'm just hitting Control Space here, to invoke the IntelliSense engine, so that we get that auto-completion. Let's make this one 10.6.5.0/24. Okay, so now we're actually using both of the address spaces that we defined for the virtual network in our subnets here. Great, so, that's basically how we build out the parameters, build out variables and resources. Now, you might ask, well, why did we create this vmSize parameter? Well, this is just an example. If you were building out a larger template that actually did declare vmSize, or Virtual Machine resources. But in this case, we're just going to use the virtual network as a simple example of how to build out a resource. Finally, we have the output section. And the output section is actually very very similar to the input parameter section. Only instead we're outputting values. So, for example, what we might want to do is grab the virtual network name and spit that out. So, we'll add a new item here called VirtualNetworkName. And then we're going to specify the output type of string. And, the value of that is going to be a reference. Actually, let's use variables, and call it VirtualNetworkName. I'm sorry, we're gonna doName. Great. So now we've declared an output parameter, we've declared input parameters, variables and resources. And as you can see, we're getting this really handy IntelliSense that helps us to build out a template. Now, typically what you'll do is you'll go ahead and build out your variables. Go ahead and build out all of your resources, and refactor things as appropriate. If you want to expose a particular property, as a parameter, then go ahead and just create the parameter for it up here in the parameter section, and then reference that parameter down here. So, for example, if we wanted to refactor out the subnet name for WebServers, then we would create a parameter for that. So we'll call it webServerSubnetName. And then we'll go ahead and specify the type of string, which is the default. And then we're going to specify the default value, which we'll just set to WebServers. And, now that we've declared this parameter, we can reference it inside of our resources. So let's go down here and say, parameters, this is an arm template function called parameters. And as you can see, it only takes one input parameter. So, the parameter's function takes the parameter name as its only parameter. So now we've parameterized this template for the WebServer subnet name. We could do the same thing with the database server's subnet name. Or, use variables, or input parameters, to define the address prefixes for those subnets. So this is just a quick introduction to how you start authoring Resource Manager templates, using Visual Studio Code.
About the Author
Trevor Sullivan is a Microsoft MVP for Windows PowerShell, and enjoys working with cloud and automation technologies. As a strong, vocal veteran of the Microsoft-centric IT field since 2004, Trevor has developed open source projects, provided significant amounts of product feedback, authored a large variety of training resources, and presented at IT functions including worldwide user groups and conferences.