This post no longer up to date. Please refer to the most recent post by Roger Best
Today we are announcing the public availability of the Azure Resource Manager Tools Preview for Visual Studio
. The Azure Resource Manager Tools preview enables you to:
- Create an application using the Azure Gallery templates
- Create and edit Azure Resource Manager deployment templates (for example a Web site with a database) and parameter files (for example you can have different settings for development, staging, and production)
- Create resource groups and deploy templates into these to simplify the creation of resources
At Build 2014
we announced the new Azure Portal
and Azure Resource Manager
. The Azure Resource Manager enables you to create reusable deployment templates that declaratively describe the resources that make up your application (for example a website and a SQL database). This simplifies the process of creating complex environments for development, testing, and production in a repeatable manner. And it provides a unified way to manage and monitor the resources that make up an application from the Azure preview portal.
With this preview you are able to create an application using the Azure Gallery Templates and define and manage your Azure resources using JSON templates. This makes it easier for you to quickly setup the environment you need to Dev/Test your application in Azure. The two key features are the Visual Studio integration with the Azure Gallery and the ability to create and edit Azure Resource Manager deployment templates.
We’ll get started using this tooling by walking through a scenario. First we’ll create a project based on a template from the Azure Gallery and we’ll look at what artifacts are added to your solution when you create your project. Then we are going to create and deploy the Azure resource group and resources we need for our application. Once we have provisioned our resource group and resources, we’ll publish our application.
Download the tools now
: Azure Resource Manager Tools Preview for Visual Studio
Azure Cloud Gallery – Create a Cloud App Project
With the Azure Resource Manager Tooling we’ve made it possible to create Visual Studio applications using the Azure Gallery templates. You can find these templates by navigating to File->New Project-> Cloud-> “Cloud App from the Azure Gallery”
after installing the Preview tools. In the screenshot below I’ve done that and called my project “MyAzureCloudApp”.
Once you create a Cloud App from the Azure Gallery, you will find a list of the available templates. We’ve made a couple of the more popular Azure Gallery templates available.
- Website – This template will create an ASP.NET Website with Application Insights.
- Website + SQL – This template will create an ASP.NET Website, a SQL Azure Server and database, and Application Insights monitoring.
While this preview only has two templates available, going forward, more templates will be added for common application scenarios that use other Azure features including caching, storage, virtual machines, and more.
For this walkthrough, we will select the Website
Your Cloud App Solution
After creating a Cloud App from the Azure Gallery, you will find the ASP.NET Website Project and a new project type - an Azure Resource Manager Deployment project called MyAzureCloudApp.Deployment
. The Deployment project includes: a deployment template file (WebSite.json
), a template parameter definition (WebSite.param.dev.json
), and a PowerShell script (Publish-AzureResourceGroup.ps1
) that can be used to deploy your resources to Azure.
Let’s take a look at each of these artifacts in your solution:
- The Deployment project is the container for our resource definitions, parameters, and a PowerShell script that can be used to deploy resources. As we’ll see later you can also right click on the Deployment project to deploy your defined resources.
- The WebSite.json file is the deployment template file where your resources are defined. This file contains all the resources that we are going to deploy later. As you might imagine, since we selected the Website template, this file contains the definitions needed to create a website. We’ll take a closer look at this later.
- The WebSite.param.dev.json contains the values for all the parameters needed by the deployment template file. For example, the name of the website is a parameter, and that value would go in this file.
Create My Azure Resources – Using the Dialog
There are a couple of ways to deploy your resources and resource group to Azure. The simplest method is to right click on the Deployment Project, and select “Deploy to Resource Group
”. This will bring up the Deploy to Resource Group
We need to create an Azure Resource Group which will contain the logical grouping of all of the resources we need for our web application. To do that click on the Resource group
combobox and select “Create New
Name your Azure Resource Group whatever you want (I’ve called mine “MyAzureCloudApp”) and give it a location. Click the Create
button when you are ready and your Azure Resource Group will automatically be provisioned for you (but with no resources yet).
Make sure you’ve selected a Deployment template (website.json), Template Parameter file (webite.param.dev.json), and a storage account as I’ve done above. If you don’t already have a storage account, you will need to create a storage account
Next click the “Edit Parameters” button. We are going to define our website name, web hosting plan name and website location so that it looks something like I’ve done here:
Let’s take a look at what each parameter means. The “siteName
” parameter is the name of your website. The “hostingPlanName
” is the Web Hosting Plan
name. A hosting plan represents features and capacity settings that you can share out across more than one website. The “siteLocation
” is just the region where our website will reside, and will be something like “West US” or “Central US” or any of the valid website regions. The “sku
” parameter we have left to a default of “Free”, and that is the website’s pricing tier
(other options are Shared, Basic, and Standard). The “workerSize
” we are also leaving to zero. This setting is used to describe the size of the virtual machine that runs your website (0=small, 1= medium, and 2=large). In this example, workerSize has no effect, since we choose a sku size of “Free”. For it to be applicable we would have to pick the sku size to be Basic or Standard.
After you fill out these parameters click the “Deploy
” button and you’ll have your resource group and resources deployed to Azure! In this case we have deployed a website inside of an Azure resource group (check it out on the new and enhanced Azure Portal
After you have deployed your resources, you’ll see that it has written the parameter values back to the WebSite.param.dev.json
file like so:
Save the JSON file so that the changes are persisted.
Publish Our Application
Now that we’ve created and deployed to the MyAzureCloudApp resource group, let’s publish our application. We’re going to publish to the website resource that we just finished provisioning when we deployed the template.
In the Solution Explorer, right click on the ASP.NET web project and select “Publish
The publish wizard will launch, and will prompt you to select a target to publish to. Select the “Microsoft Azure Websites
” publish target.
We will now get a list of Azure Websites in our Azure subscription. Go ahead and select the one you just created (I’ve selected “mattsWebSite”). Click OK when you are done.
All the necessary publish settings will automatically be populated in the Publish Wizard. So all you need to do now is click the “Publish” button. After a short wait your web application will publish, and your website will launch in your web browser. At this point your web application has now been published to the website resource in the MyAzureCloudApp resource group.
So now that we’ve published, let’s take a look at another way that you can create an Azure Resource Group and deploy Azure resources.
Deploy My Azure Resources – Using PowerShell
The second way to create a resource group in Azure is to run the PowerShell script provided as part of the Deployment project (Publish-AzureResourceGroup.ps1
). The script leverages the latest Azure PowerShell
(at least version 0.8.3 or later) to deploy your resource groups and resources.
Before running, you’ll need to ensure that the Website.param.dev.json
file contains the correct name of your website, hosting plan, and web site location. Make sure you save your changes.
Notice below I’ve changed the website name to “mattsAwesomeSite”.
You’ll want to change your website name as well. I did this so to make sure that it creates a new website for me.
Just to show something off here, go ahead and double click on the Publish-AzureResourceGroup.ps1
file to bring it up in the document window in Visual Studio (in case you haven’t seen yet, we’ve added coloring for PowerShell scripts).
After that, you can right click on the Publish-AzureResourceGroup.ps1
file, select “Open with PowerShell ISE
This will launch the PowerShell ISE. You can run the PowerShell script at this point. But just to make sure you have an error free experience, double check a few things:
1) Have you installed Azure PowerShell
yet (at least version 0.8.3)?
a. You can install this using Web Platform Installer. Just select “Microsoft Azure PowerShell”
2) If you haven’t done much with PowerShell before, then you probably need to set the execution policy to allow PowerShell scripts to run. To do this you need to run “Set-ExecutionPolicy RemoteSigned
” from the PowerShell ISE to allow remote signed scripts like ours to execute (note: you must run this command as an administrator). You’ll be prompted with a dialog to confirm that you want to change your policy settings.
3) Make sure you’ve run the Azure PowerShell command “Add-AzureAccount
” to login your Azure account to the current PowerShell session. A dialog will display and you’ll be prompted to enter in your Azure credentials.
4) Does your Azure subscription have a default storage account? If not then you can set this a couple of ways.
a. One way is to set the current azure storage account for this session by running “Set-AzureSubscription -CurrentStorageAccountName ‘yourstorageaccount’”
b. Another way is to just edit the PowerShell script (Publish-AzureResourceGroup.ps1) to have a new parameter “–StorageAccountName myStorageAccount” (something like this: New-AzureResourceGroup ... -StorageAccountName 'defaultstoragerms')
Go ahead and run the PowerShell Script now: “> .\Publish-AzureResourceGroup.ps1”
You will be prompted for a location of the resource group, which is any valid region (I’ve picked “West US”).
After a few seconds, the PowerShell script should complete. The script also provides some great verbose output, so you can clearly see what resources were made, and what errors (if any) were encountered:
The script we give you uses the Azure PowerShell
cmdlets to create an Azure Resource Group if one does not exist (which is specified by the –Name parameter in the script). The script passes along the WebSite.json
files to the Azure Resource Manager service which figures out exactly what Azure resources need to be deployed.
When the script is complete, you’ll find that your Azure resource group, and the Azure resources you specified have been created for you (just as we did in the previous example) and you can view these in the Azure Portal
Wrapping it up
After all this we’ve now introduced you to the preview release of the Azure Resource Manager tooling. We’ve shown you how you can create projects in Visual Studio based off of the Azure Gallery Templates. And how you can define and deploy your Azure resource groups and resources using our tooling. Azure Resource Groups really are a great way to setup the environment you need to host your application. And combined with this tooling, you should have a better development and testing experience with Visual Studio and Azure.
Thanks for reading and let us know what you think in the comments below!