Thursday, January 21, 2016

Deploying a Azure Resource Manager (ARM) JSON Template

For the non-developers in us, it's a lot more harder than it looks.


  1. Using Web Platform Install, install the following (https://www.microsoft.com/web/downloads/platform.aspx)
    1. Install Visual Studio Community 2015
      1. Make sure that the "Microsoft SQL Server Data Tools" is installed, if not, then you can add it later in Add/Remove Programs
    2. Install Azure Tools
    3. Install Azure PowerShell 1.0
  2. Run Visual Studio Community 2015 with Administrator rights - make sure it's admin rights or else your deployment (which runs Azure PowerShell in the background) will fail with very odd error messages! (See error below)
  3. Create new project
    1. File > New > Project > Installed > Templates > Visual Basic > Cloud > Azure Resource Group
  4. Pick a Azure Template, I recommend "Blank Template" from Microsoft to start with
  5. Under Solution Explorer (on right), expand Templates > azuredeploy.json
  6. Click "JSON Outline" on bottom left and start creating resources by clicking "Add Resource"
  7. When template is complete, right click on "AzureResourceGroup" under Solution Explorer and select Deploy.

If you forgot to run Visual Studio Community 2015 without admin rights, you will get the following cryptic messages:

14:04:09 - Build started.
14:04:09 - Project "AzureResourceGroup2.deployproj" (StageArtifacts target(s)):
14:04:09 - Project "AzureResourceGroup2.deployproj" (ContentFilesProjectOutputGroup target(s)):
14:04:09 - Done building project "AzureResourceGroup2.deployproj".
14:04:09 - Done building project "AzureResourceGroup2.deployproj".
14:04:09 - Build succeeded.
14:04:09 - The following parameter values will be used for this deployment:
14:04:09 - Launching deployment PowerShell script with the following command:
14:04:09 - 'c:\users\username\documents\visual studio 2015\projects\azureresourcegroup2\azureresourcegroup2\Scripts\Deploy-AzureResourceGroup.ps1' -StorageAccountName '' -ResourceGroupName 'RG_Test1' -ResourceGroupLocation 'southeastasia' -TemplateFile 'c:\users\username\documents\visual studio 2015\projects\azureresourcegroup2\azureresourcegroup2\templates\azuredeploy.json' -TemplateParametersFile 'c:\users\username\documents\visual studio 2015\projects\azureresourcegroup2\azureresourcegroup2\templates\azuredeploy.parameters.json' -ArtifactStagingDirectory '..\bin\Debug\staging'
14:04:09 - Get-AzureEnvironment : The term 'Get-AzureEnvironment' is not recognized as the name of a cmdlet, function, script 
14:04:09 - file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct 
14:04:09 - and try again.
14:04:09 - At line:1 char:174
14:04:09 - + ... zure_PS_Data_Collection = 'true' }; if ((Get-AzureEnvironment -Name ' ...
14:04:09 - +                                              ~~~~~~~~~~~~~~~~~~~~
14:04:09 -     + CategoryInfo          : ObjectNotFound: (Get-AzureEnvironment:String) [], CommandNotFoundException
14:04:09 -     + FullyQualifiedErrorId : CommandNotFoundException
14:04:09 -  
14:04:10 - Get-AzureEnvironment : The term 'Get-AzureEnvironment' is not recognized as the name of a cmdlet, function, script 
14:04:10 - file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct 
14:04:10 - and try again.
14:04:10 - At line:1 char:2183
14:04:10 - + ... user@company.com' -Environment (Get-AzureEnvironment -Name ' ...
14:04:10 - +                                              ~~~~~~~~~~~~~~~~~~~~
14:04:10 -     + CategoryInfo          : ObjectNotFound: (Get-AzureEnvironment:String) [], CommandNotFoundException
14:04:10 -     + FullyQualifiedErrorId : CommandNotFoundException
14:04:10 -  
14:04:10 - & : The script 'Deploy-AzureResourceGroup.ps1' cannot be run because the following modules that are specified by the 
14:04:10 - "#requires" statements of the script are missing: AzureRM.Resources.
14:04:10 - At line:1 char:2227
14:04:10 - + ... eCloud')));&'c:\users\username\documents\visual studio 2015\projects\ ...
14:04:10 - +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14:04:10 -     + CategoryInfo          : ResourceUnavailable: (Deploy-AzureResourceGroup.ps1:String) [], ScriptRequiresException
14:04:10 -     + FullyQualifiedErrorId : ScriptRequiresMissingModules
14:04:10 -  
14:04:10 - Deploying template using PowerShell script failed.
14:04:10 - Tell us about your experience at http://go.microsoft.com/fwlink/?LinkId=691202

So make sure you "Run as administrator"!