image
Deploying a Resource by Using a Template
Start course
Difficulty
Intermediate
Duration
29m
Students
2179
Ratings
4.8/5
Description

In this course, I’ll start with an overview of Azure Resource Manager templates. Then I’ll show you how to build a template from scratch and deploy an Azure Storage account with it. Next, I’ll show you how to use a template to deploy a virtual machine, which is a more complicated resource. After that, I’ll explain how to make your templates more usable by adding parameters and variables. Finally, I’ll show you how to make your templates more sophisticated by using functions.

Learning Objectives

  • Describe the structure of Azure Resource Manager templates
  • Build an ARM template and use it to deploy a resource
  • Use an ARM template to deploy a virtual machine
  • Use parameters and variables in an ARM template
  • Use functions in an ARM template

Intended Audience

  • Azure administrators and developers

Prerequisites

  • Basic knowledge of Azure Virtual Machines, Azure Storage, and Azure Virtual Networks
Transcript

Suppose you want to write a template that you can use to create a new storage account, and you can’t find an example template that has everything you need in it. Trying to write an ARM template yourself is a bit of a daunting task, but luckily, there’s a way to make it easier. If you install the Azure Resource Manager tools extension in Visual Studio Code, you can build new templates relatively quickly.

I’m not going to show you how to install VS Code or the ARM extension, but I’ve included links to their download pages in the transcript below.

https://code.visualstudio.com/

https://marketplace.visualstudio.com/items?itemName=msazurermtools.azurerm-vscode-tools

Once you’ve installed both of them, go into VS Code’s File menu and select “New file”. Let’s call it “storage.json”. Now type “arm” on the first line. It gives you some basic ARM templates to choose from. Select the first one. It gives us a blank template.

That’s a good start, but how do we fill in all of the details? Go to the “resources” section and put your cursor between the square brackets. Then start typing the resource you need. We want to define a storage account, so start typing “storage”. It gives us quite a few choices, but we should select the first one: “arm-storage”.

It filled in all of the basics for a storage account. It also highlighted some values we might want to change. We definitely need to change the name of the account because it has to be unique across all of Azure Storage. I’ll call it “castorage3”. Notice that it changed the name in two places when I typed it: the name and the displayName.

To get to the next value, hit the Tab key. “StorageV2” is the normal kind of storage account, so we’ll leave that. Hit Tab again. Premium_LRS is expensive, so let’s change it to a cheaper one. To get a list of potential choices, you have to delete this, and then hit Ctrl-Space. Let’s pick “Standard_LRS”. Now we need to delete the value for the tier as well. Delete it, hit Ctrl-Space, and select “Standard”. Then save the file.

Okay, believe it or not, this is a complete template. It doesn’t have parameters or outputs or anything like that, but it should work.

Now, to do a deployment, we need to open a terminal window. Go into the Terminal menu and select “New Terminal”. First, you need to log in to Azure. Type “az login”. Select your account. And that’s it. You can close this tab.

Now type the command to do the deployment, which is “az deployment group create”. Then add “--resource-group” and type the name of the resource group where you want to deploy the storage account. If you don’t already have one, go the Azure Portal and create one there. Okay, I’m going to use a resource group I have called “examplerg”. Then type “--template-file” and the name of the file, which we called storage.json. Hit “Enter”. It’ll take a little while, so I’ll fast forward. 

It’s done. Let’s have a look at the examplerg resource group in the portal. It worked. There’s the new castorage3 account.

About the Author
Students
216939
Courses
98
Learning Paths
164

Guy launched his first training website in 1995 and he's been helping people learn IT technologies ever since. He has been a sysadmin, instructor, sales engineer, IT manager, and entrepreneur. In his most recent venture, he founded and led a cloud-based training infrastructure company that provided virtual labs for some of the largest software vendors in the world. Guy’s passion is making complex technology easy to understand. His activities outside of work have included riding an elephant and skydiving (although not at the same time).