Previously known as Azure Resource Manager Tooling Preview
The Azure Resource Manager 2.5 for Visual Studio 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.
The Azure Resource Manager enables you to create reusable deployment templates that declaratively describe the resources that make up your application (for example an Azure Website and a SQL Azure 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.
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 web site based on a Cloud Deployment project 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, which will include publishing of our application.
This tooling is available in the Azure SDK 2.5 for .NET [download for VS 2013 | VS 2015 Preview]
Create a website with a Cloud Deployment 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 Deployment Project” after installing the SDK In the screenshot below I’ve done that and called my project “MyAzureCloudApp”.
Once you create a Cloud Deployment Project, 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 Azure Website (with automatic publishing and Application Insightsmonitoring).
- Website + SQL – This template will create an Azure Website (with automatic publishing and Application Insightsmonitoring) and a SQL Azure Server with database.
- Website + SQL + Redis – This template will create an Azure Website (with automatic publishing and Application Insights monitoring), a SQL Azure Server with database, and a Redis Cache.
While this release only has three templates available, going forward, more templates will be added for common application scenarios that use other Azure features including networking, storage, virtual machines and more.
For this walkthrough, we will select the Website + SQL template.
Your Cloud App Solution
After selecting an ASP .NET application in the wizard , 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 reference to the web project, a deployment template file (WebSiteDeploySQL.json), a template parameter definition (WebSiteDeploySQL.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 reference MyAzureCloudApp connects the web project to the deployment project and has properties for the package location, web deploy package file and actions to Build and Package.
The WebSiteDeploySQL.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 + SQL template, this file contains the definitions needed to create a website and a SQL Azure database. We’ll take a closer look at this later.
The WebSiteDeploySQL.param.dev.json contains the values for the non-default 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 / New Deployment…
You may not run into the Select a deployment type dialog as it is only enabled with the proper configuration. I’ll talk about the Environment option later in this walkthrough, but now select Resource group and this will bring up the Deploy to Resource Group dialog.
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 combo box and select “Create New”.
Name your Azure Resource Group whatever you want (I’ve used the default which is based on the solution name “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 (WebSiteDeploySQL.json), Template Parameter file (WebSiteDeploySQL.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 before continuing.
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:
The red exclamation marks are required parameters that we’ll have to add. Below is a table with information on each parameter.
|dropLocation||An auto-generated location for the web deployment package. The dropLocation is a folder in the Azure storage that was entered in the “Deploy to Resource Group” dialog, where the webSitePackage will be copied to.|
|dropLocationSasToken||An auto-generated security key.|
|webSitePackage||The name of the web deployment package, the deployment project references properties has more information on the dropLocation and the webSitePackage.|
|webSiteName||This parameter is the name of your website.|
|webSiteHostingPlanName||This is the Web Hosting Plan name. A hosting plan represents features and capacity settings that you can share out across more than one website.|
|webSiteLocation||The region where our website will reside, and will be something like “West US” or “Central US” or any of the valid website regions.|
|weSiteHostingPlanSku||Default to “Free”, and this is the website’s pricing tier(other options are Shared, Basic, and Standard).|
|webSiteHostingPlanWorkerSize||Default 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 and then you would need to select the appropriate workerSize.|
|sqlServerName||The name of the Azure SQL Server.|
|sqlServerLocation||The location of the Azure SQL Server.|
|sqlServerAdminLogin||The administrator name for the SQL server.|
|sqlServerAdminPassword||The password for the administrator.|
|sqlDbName||The name of the database created in the server.|
|sqlDbCollation||SQL Server Collation Support|
|sqlDbEdition||Azure SQL Database Service Tiers|
|sqlDbMaxSizeBytes||Database Size Limits|
|sqlDbServiceObjectiveId||Edition Performance Levels|
The “Save Passwords” check box will store the password into the JSON file, but it will be stored as plain text so you need to be extra diligent with this option.
After you fill out these parameters click the “Deploy” button or if you have edited the parameters, as in this example, the “Save” and then “Deploy” and you’ll have your resource group and resources deployed to Azure! In this case we have deployed a website with your custom web application 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 WebSiteDeploySQL.param.dev.json file like so:
Save the JSON file so that the changes are persisted. The WebSiteDeploySQL.param.dev.json will have “null” for the parameter values if you haven’t deployed the resource group or edited the parameters.The deployment output is sent to the Azure Provisioning windows.
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).
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 WebSiteDeploySQL.json and WebSiteDeploySQL.param.dev.json files to the Azure Resource Manager service which figures out exactly what Azure resources need to be deployed.
Before running, you’ll need to ensure that the WebsiteDeploySQL.param.dev.json file contains the correct name of your website, hosting plan, web site location, and SQL parameters. 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:
- Have you installed Azure PowerShell yet (at least version 0.8.3)?
- You can install using Web Platform Installer. Just select “Microsoft Azure PowerShell”.
- 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.
- 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.
Go ahead and run the PowerShell Script now: “> .\Publish-AzureResourceGroup.ps1”
You will be prompted for the storage location and the 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:
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.
Deploying to Environment
For more information about the Environment deployment.
Wrapping it up
After all this we’ve now introduced you to the Cloud Deployment Project. 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. We have a survey to help get feedback for current and future improvements at http://www.instant.ly/s/TQnbZ.