DEMO: Simple Template
Start course
Difficulty
Intermediate
Duration
52m
Students
11043
Ratings
4.1/5
starstarstarstarstar-border
Description

The Azure cloud is a collection of resources that work in unison to deliver a product or a service. Hardware is virtual and services can be created and destroyed at the stroke of a key. In the context of DevOps, resources can be "spun up" as part of a pipeline. It is crucial that when resources are deployed multiple times, those deployments are consistent, repeatable, and can be automated. Doing it manually through the Azure portal isn’t practical. Azure Resource Manager (ARM) has an interface for processing resource templates that specify resource deployments.

In this course, we look at how those templates can be built and deployed. We start with a simple template and move on to more complex examples to illustrate many of the useful features available when deploying resources with templates. This course contains plenty of demonstrations from the Azure platform so you can see exactly how to use Azure Resource Manager in practice.

If you have any feedback on this course, please reach out to us at support@cloudacademy.com.

Learning Objectives

  • Understand what Azure Resource Manager (ARM) is and its use cases
  • Learn about the different ARM templates available and how they can be used
  • Deploy databases using an ARM template
  • Export a template and create templates using QuickStart templates
  • Deploy resources using a script

Intended Audience

This is a beginner-level course aimed at anyone who wants to learn more about managing and configuring their Azure environment, and fast-tracking their deployments.

Prerequisites

To get the most out of this course, you should have a basic understanding of the Azure platform.

 

GitHub Repo

https://github.com/cloudacademy/intro-to-arm

 

Transcript

I know what you're thinking, this is very complex, and where do I start? Well, as luck would have it, Visual Studio has some fantastic features for creating and editing ARM templates. To access the ARM template intellisense, you need to have the Azure Resource Manager Tools extension installed in VS Code.

First thing I'm going to do is create a new file, and save it with the JSON extension. Straightaway, we can see that VS Code recognizes this as a JSON file. This is where the magic starts, or more correctly intellisense, when I type ARM for Azure Resource Management. We can see I have code auto-complete here with some prompts. I'm just going to select the top one, which is a resource group template and there we have all the sections that we have talked about earlier. So if I want to create a simple web app deployment, all I have to do is go into resources and once again type ARM, and we can see here we have a lot of resources to choose from.

Now this is all context-based, and I'm going to select web app, and there we have all the properties that we need to create a web app deployment. Obviously, I don't want my app to be called webApp1. So I'm going to create a parameter of type string, called appname. We can see here with the yellow squiggly line that part of the template functionality is that it recognizes that I haven't used that parameter yet. So, I'll go down here and type open square bracket P and you see the auto-complete prompts with parameters. I'll pick parameters and type open bracket and I'm prompted with the parameter appname. I can then go and I can just replace all the instances of webApp1 with my appname parameter. Every resource has a type and in this case it's a web site and it's already put in the ARM tags and properties for us.

In the dependsOn section, we can see a service plan. But before I define that I'm going to show you how we can test our template before deploying it. If I go to my PowerShell window, which I've already logged into Azure and enter Test AzResourceGroupDeployment, I'm prompted for the parameter appname, which I'll supply, called howdeploywebapp. It's returned with an invalid template error. It's complaining that it doesn't have an appServicePlan1.

Okay, so I need to back in the resources section and I will add a service plan and I will also add another parameter called planname. I can use that parameter everywhere I've got appServicePlan1, and that is even within the app service itself, like in this concat function. As you can see, functions, parameters and variables are used within square brackets.  The error in the concat function indicates a missing comma. Right, so I'll save that. Just notice here that the location is picked up from the resource group.

So when we are testing, we are testing it with AzResourceGroupDeployment, and that relies on the fact that it belongs to an existing resource group as opposed to using the Test-AzDeployment command. I'll go back here and re-run this, howdeploywebbapp and the plan name is howdeployplan and we can see that has been successful. So let's go ahead and deploy that. I'll just go back here and change my test to new. Now we can go over to the portal and see what's happening. If I refresh deployments, we can see we've got a deployment happening. Let's click on that and go into it, and it's complete. I'll navigate back to the resource group home page so we can see the newly created resources.

 

Right, so here we have the plan and the app, and as you would expect. Clicking on the app service resource takes us to the app service, where we can click on the app service URL to see it deployed.

 

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "appname": {
            "type": "string",
            "metadata": {
                "description": "description"
            }
        },
        "planname": {
            "type": "string",
            "metadata": {
                "description": "description"
            }
        }        
    },
    "functions": [],
    "variables": {},
    "resources": [
        {
            "name": "[parameters('planname')]",
            "type": "Microsoft.Web/serverfarms",
            "apiVersion": "2018-02-01",
            "location": "[resourceGroup().location]",
            "sku": {
                "name": "F1",
                "capacity": 1
            },
            "tags": {
                "displayName": "[parameters('planname')]"
            },
            "properties": {
                "name": "[parameters('planname')]"
            }
        },
        {
            "name": "[parameters('appname')]",
            "type": "Microsoft.Web/sites",
            "apiVersion": "2018-11-01",
            "location": "[resourceGroup().location]",
            "tags": {
                "[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('planname'))]": "Resource",
                "displayName": "[parameters('appname')]"
            },
            "dependsOn": [
                "[resourceId('Microsoft.Web/serverfarms', parameters('planname'))]"
            ],
            "properties": {
                "name": "[parameters('appname')]",
                "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('planname'))]"
            }
        }
    ],
    "outputs": {}
    }
 
}
About the Author
Students
17700
Courses
62
Learning Paths
12

Hallam is a software architect with over 20 years experience across a wide range of industries. He began his software career as a  Delphi/Interbase disciple but changed his allegiance to Microsoft with its deep and broad ecosystem. While Hallam has designed and crafted custom software utilizing web, mobile and desktop technologies, good quality reliable data is the key to a successful solution. The challenge of quickly turning data into useful information for digestion by humans and machines has led Hallam to specialize in database design and process automation. Showing customers how leverage new technology to change and improve their business processes is one of the key drivers keeping Hallam coming back to the keyboard.