Azure Resource Manager
The course is part of these learning pathsSee 4 more
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 email@example.com.
- 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
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.
To get the most out of this course, you should have a basic understanding of the Azure platform.
As I've said the demos so far have been a little contrived. Now I want to show you a few of the more advanced features of ARM templates like the use of user-defined functions and how to create multiple instances of a resource type using something that could be called a looping mechanism. We will then deploy that template via a PowerShell script which will involve creating a new resource group and then submitting the template parameters using a template object. Let's begin by creating a new template. I'm going to call it arm deploy and once again that will be a resource group template. In terms of resources, we are going to need a database server and then obviously some databases to run on that server. From the ARM template autocomplete I’ll select arm-sql-server and then arm-sql-db for my resources.
For parameters, I will need a server name and because I am creating more than one database I'm going to need a parameter that lets me tell the template how I databases I want. I will call that dbcount. Because we are accessing Azure SQL I will also need to provide an IP address for the database firewall. That will be startip and endip to define the IP address range. In terms of naming the databases, I'm going to call them test_db and that name will have a number appended to it, and also define an admin name and password. I'm defining these as variables to demonstrate the variable use, but you could just as well pass them in as parameters. I’ll replace SqlServer1 with the servername parameter, which will have to be changed in several places. I'll also replace the administrator login and password with my variables. Next, I'll replace the firewall start IP and end IP addresses with the corresponding parameters.
When it comes to the database name this is where it all gets a little bit interesting. So the database name is made up of the server name/followed by the database name so the first thing I'm going to have to do is concatenate my server name parameter with the database name. But of course, the database name is a compound of the DB prefix variable plus the database number. To make up this compound name I'm going to define a function that will return the name. Let's go into the functions section and we'll look for arm-user, which is for user-defined function. I'll give my function a name of databasename, and like all functions it takes parameters. This is where the auto complete doesn't fully meet expectations. The function section has to have a namespace property and all functions have to be defined within a members section of the functions section. I'll need a parameter for my database name prefix and I will need an integer parameter for the number that will be appended to the name. The return value or output is a string and it is a concatenation of name prefix and index, which I’ll join together with the built-in conact function. Going back to the database name I will use the databasename function firstly by starting with the namespace and the function name. Then I will use the DB prefix variable as my first parameter and then a built-in function called copy index. I guess you could say copyindex is a little bit like the index of a for loop, although we have yet to tell the database template to make copies. I'll just replace the SqlServer1 text with the server name parameter in the depends on section for my database, as obviously, a database does depend on a database server. Now I'll add the copy section. So it has a name and it has a count and that count is the number of copies to make and I will get that from my dbcount parameter. I'll just replace the display name and tags with my compound database name.
Now that we are done with the template let's move on to the PowerShell script. So this is going to be called dbarmdeploy.ps1 and Visual Studio Code recognizes the file extension and that I'm working with a PowerShell script and it is doing a nice job of syntax highlighting for me. So I'll start by declaring a resource group variable and I will give it a name and a location. The location is the Azure abbreviation for the West US region. Next, I want to issue the command to create a new resource group. So that's New-AzResourceGroup with a name and the location, which is the location element of the resource group variable. Next, I'm going to create a compound template variable which will have the name of my template as file name and nested within it the parameters that I want to submit. So that will be server name dbcount, startip and endip. I'll create a new deployment with New-AzResourceGroupDeployment and use the resource group variable to get the ResourceGroupName parameter. Then the template variable to get the file name for -TemplateFile and then the template parameters object will be for the -TemplateParameterObject parameter, my word that's a mouthful of parameters. Just in case that wasn’t clear, the TemplateParameterObject is a compound parameter, whereas the other parameters are strings. Right, let's save that and go to the PowerShell command prompt, and run the script. Straightaway we can see the resource group has been created so that's a good start, and if we pop over to the portal we can see that the deployment is running. If I open up an Azure SDK command prompt I can issue a deployment group list command to see which deployments are running for my resource group. At the top, I can see the name of the deployment is armdeploy so using that I can issue and az deployment group show command with my resource group and then the name of the deployment. This will also return all the details of the deployment plus the provisioning state at the bottom which is currently showing it as running.
Okay, the server has been deployed and Azure resource manager has accepted the database deployments. Going back to the PowerShell window we can see that the whole deployment has finished successfully and it returns our input parameters. I'll just open up SQL Server management and log into the database server and check out my to test databases. Finally, I will remove the resource group with the force parameter so I'm not prompted.
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.