Skip main navigation

New offer! Get 30% off your first 2 months of Unlimited Monthly. Start your subscription for just £29.99 £19.99. New subscribers only. T&Cs apply

Find out more

Azure Resource Manager Templates and Visual Studio

Hello and welcome back to this video on ARM and Visual Studio. So far in the training, we’ve covered the basics of ARM. We looked at what it takes to create an ARM template. We looked at Visual Studio code. With the extension that it offers, you can quite easily create templates. But if you are doing much more than just creating templates, you’re looking at combining that with your application, you kind of need to do that within the IDE. And what’s great is that Visual Studio IDE has out-of-box integration with ARM, which not only allows you to create your templates but provides you a way of deploying the templates right from within Visual Studio.
And I think that’s really, really useful, especially when you’re trying to test your templates as part of the creation process. So in this video, we’ll focus on reviewing the integration between Visual Studio and ARM. At the same time, we will do a Hello, World project by creating a new resource group project within Visual Studio, start by assembling a template, and look at how easy it is to create ARM templates within Visual Studio. All right. So let me switch right into the demo, then. In the demo, we are going to cover the integration between Azure and Visual Studio. We’ll look at authoring a simple template in Visual Studio and then look at deploying a template right from within Visual Studio. OK.
So I am within the Azure portal. I just want to quickly load up the resource group blade and show you that I don’t have a resource group called iactraining-demo.
Because we’re going to create one using Visual Studio. All right. So I’m going to launch Visual Studio here. I’m using the Visual Studio 2017 version. But this tooling is available in 2015. This tooling has been available in 2013 as well. Of course, the tooling gets better with the most up-to-date version of Visual Studio. You don’t need to be a user of Visual Studio Enterprise to get this feature. It’s available in the Community edition, which is free. All right. So if I going to File, New, and Project, I will see under this section that I have a Cloud subheading. If I click on Cloud, I get access to a lot of the cloud-based templates that are available within Visual Studio.
Now, if you come here and you don’t see these options, chances are you don’t have the Azure SDK installed. The Azure SDK is what enables the templates in Visual Studio. Again, that’s free as well. So if you don’t have it, navigate to the Azure homepage. And from there, you get the option to download the SDK. The SDK is not only available for .NET, but it’s available across platform. It’s available for other programming languages as well. Now, because I have it set up, I have these templates available. I’m just simply going to choose the Azure Resource Group template. And let’s call this IaCTrainingArm.
And let’s call the solution IaCTraining. I’m not going to create a separate Git repository for this. But just select the defaults and click OK. Now, what you get at this point is an option to preselect the template or the resources that you want to embed within the template. For now, I’m going to select Blank so that we can work our way from there. But if you were planning to set up an ARM template for a specific resource type, then you could just come in here, search for that resource– for example, web app– and then just say OK. Next thing, you have a template that’s ready, enabled for web app-specific resource types. So let’s go back and select the Blank.
And click OK.
It’s just creating the project type for me behind the scenes. It usually takes a couple of minutes. I flip to the Solution Explorer, I can see that the project’s already there. And as a default, the project gets certain files. It gets the Azuredeploy.JSON file. And as we looked at it, yesterday there’s a bare minimum syntax format that you need in order to create ARM templates. So the default blank template kind of has that for you. It also provides you with a parameters file. And it gives you a deploy PowerShell script.
So without even making any changes here, if I came in to the project level, right-clicked, and said I want to deploy this, it gives me an option to connect to my Azure subscription. And then leveraging the deployazureresourcegroup.PS1, I’d just be able to deploy this resource group without having to go into PowerShell or any other ISE. The other thing you have available is the JSON outline. So if I click on the JSON outline, I can see a crisp view of all the components that I have available within my resource group template here.
Now, if I wanted to add a new resource, I could just simply click here, right-click and say Add New Resource, which brings me back to the same resource option window that I had initially when I was creating the template. So let’s select a past resource. Let’s select something like a web app. And call it IaCDemoWebApp. Now it asks me what service plan I want to use for my web app. I’m just going to create a new subscription plan and call it Basic. Click Add. Next thing, if I click Add, it basically generates all the code for me behind the scenes. And let’s have a look at the code. So it’s added a few parameters like the name, the SKU.
It’s added the variables. It’s added the resource. So I don’t really need to go in and type all of that out myself. And see, it’s even figured out the dependencies. So as part of setting it up, it’s saying I need to do this first, and then I need to do that. So you kind of don’t have to worry about setting that up yourself. And then onwards from there, it also has the output section. So I can come in, and say I want to output the web app name. And then that is just probably the parameter. That is just simply the parameter name from here.
There we go. So at this point, if I compile it, I’m ready to go. My template’s ready. So let’s experiment by trying to deploy this. So let’s right-click, select Deploy, click New. I’m going to choose the Enterprise description that I’ve been doing the rest of the demos on. So just bear with me while this renders.
All right. So I’m going to select the Enterprise description here.
Because I’ve got access to a few subscriptions, I just need to select the one I want to do the deployment in. Now, I have the option of deploying in an existing resource group or creating a new one. So let’s create a new one and call it IaCTrainingDemo.
And select the location West Europe. Click Create. Now, behind the scenes, it’s actually firing the API up to create the resource group. If I flip back into the Azure portal, you click Refresh. There’s my resource group created. Clearly, at this point, it wouldn’t have any resources in it because we’re yet to deploy the template. So coming back here, if I click Deploy, it saying, well, you haven’t told me what parameters you need, specify the parameter values that you want to inject into the template. So let’s call it–
click Save.
Now, at this point, it’s just executing. It’s validated the template. It’s now executing the deployment behind the scenes using the API to do it. And it’s quite descriptive in the output here. I can see that I’ve called the web app Basic. And the default SKU has been selected for me already, and the subscription details of where it’s being deployed, the target. And then there are some errors on the way. I think the error has been introduced because of the output value that I added. So I’m just going to quickly remove this and try and redeploy this once again.
All right. Deploy into the existing resource group that we just created, and click Deploy. It’s working its way up from there again. The template is valid. It was definitely something I added in the output section in the template that was causing the issue. Now, if I flip into the Azure portal, hopefully, in the next few minutes, the resources should start to show up. Again, you can keep monitoring it from the output window.
As you can see here, it’s reported that the resource Microsoft.Web/serverfarm basic provisioning status is succeeded. So the web farm has been provisioned. Now the first web app would be deployed. So if we flip back to Visual Studio, it’s actually doing it. It’s deployed the site as well. And the status of that is successful as well. So if I come back here and click Refresh, I’ve actually got the web app deployed here. So let’s click on it. We can see all the properties of the web app. In the Essentials section, you’d find useful information like who was it deployed by, what’s the description, what resource group, and of course, the URL of the endpoint. There we go.
All it took was under five minutes to set up our new team a new project within Visual Studio. We leveraged the resource group template provided by the Azure SDK that you can see here. And then, just simply from the Helper window, we were able to select what template type we needed, and then just right-click within Visual Studio to deploy the template. Now, if you find yourself in a situation where you’re struggling to assemble the template, then as I said yesterday, it’s probably worth taking some inspiration from the GitHub repository on Azure Quickstart Templates. Now, this repository has a lot of useful templates.
If you’re planning to do things like blockchain, for example, there’s a template available for blockchain already which sets up a test environment. If you’re planning to do something with Azure Search, for example, [INAUDIBLE] there is a template available for that as well. So it’s community-supported. If you create your own templates that you fancy sharing, then please contribute on the GitHub repository here.

In the previous step, you learned about Azure Resource Manager, how to create an Azure Resource Manager template, and how to use Visual Studio code.

In this step, we’ll explore the integration between Visual Studio and Azure Resource Manager. We’ll focus on creating a resource group project and templates from within Visual Studio.

Creating an Azure Resource Group Project with Visual Studio:

Visual Studio (2013 and newer) and the Azure SDK (2.6 and newer) allows you to edit Azure Resource Manager JSON templates, which define the resources you deploy to Azure. Visual Studio provides many different starter templates for deploying common scenarios.

To deploy code with your infrastructure:

  1. Create an Azure Resource Group project in Visual Studio by choosing File > New Project, and then C# or Visual Basic.

  2. Select Cloud and the Azure Resource Group project. There are many different template options to choose from based on the type of project that you want to deploy:


  1. Customise the template to fulfil your scenario.

  2. Deploy your project from Visual Studio by choosing Deploy > New Deployment from the shortcut menu of the deployment project node:


  1. From the Resource group drop-down box of the Deploy to Resource Group dialogue box, choose an existing group or create a new one:


  1. Select the Edit Parameters button and provide values for the empty parameters and save.

  2. Select the Deploy button.

When you open the Azure portal and sign in to your account, you should see all the deployed resources after selecting Resource groups and the resource group to which you deployed. The Storage account name may add a string of characters to the name you provided to ensure a unique name.

Azure Resource Group Deployment Task

A recommended Azure deployment option from Visual Studio is to create or update a resource group with the Azure Resource Manager templates by using the Azure Resource Group Deployment Task in a continuous deployment pipeline.

To configure continuous deployment by using the built-in tasks:

  1. Edit your Visual Studio build definition to add two new build steps.
  2. Choose the build definition under the Build definitions category.
  3. Choose the Edit link:

AR DEPLOYMENT TASK 01 4. Add the new build steps to the build definition by selecting the Add build step button. 5. Choose Deploy > Azure File Copy task > Add:

AR DEPLOYMENT TASK 02 6. Select the Azure Resource Group Deployment task > Add. 7. Select Close the Task Catalog:

AR DEPLOYMENT TASK 03 8. Choose the Azure Resource Group Deployment build step and fill in the values:

AR DEPLOYMENT TASK 04 9. Override Template Parameter code:

-_artifactsLocation $(artifactsLocation) -_artifactsLocationSasToken (ConvertTo-SecureString -String "$(artifactsLocationSasToken)" -AsPlainText -Force)

10. Save the build definition and choose Queue new build.

Deploying Infrastructure Code to Azure with Visual Studio

To deploy code with your infrastructure:

  1. Add a new project to your Visual Studio solution. For example, ASP.Net Web Application:


  1. Select MVC and unselect the Host in the cloud check box because the resource group project will take care of this task.

  2. Make sure that your resource group project is aware of the new project by going back to your resource group project and right-clicking References, select Add Reference and then select the project you created:


  1. View the three key properties that were automatically set when you linked the project you created to the resource group project in the Properties window:


  1. Add a resource to the template, for example, Web Deploy for Web Apps:


  1. Redeploy your resource group project and set new parameters.
  2. Verify by selecting your web app in the Azure portal and select the URL to verify the app deployed to the site.
This article is from the free online

Microsoft Future Ready: DevOps Development, Implementation and Azure Automation

Created by
FutureLearn - Learning For Life

Reach your personal and professional goals

Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.

Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.

Start Learning now