(Part One of this series can be found here.)

Deploying Azure ARM Templates with PowerShell

After you’ve created your template, you can use PowerShell to kick off the deployment process. PowerShell is a great tool with a ton of features to help automate Azure processes. In order to deploy Azure ARM Templates with PowerShell, you will need to install the Azure PowerShell cmdlets. You can do this by simply running the command Install-Module AzureRM inside a PowerShell session.

Check out this link for more information on installing Azure PowerShell cmdlets. PowerShell works best on a Windows platform, although there is a version now out for Mac that you can check out here. You can also use Azure CLI to do the same thing. PowerShell and Azure CLI are quick and easy ways to create resources without using the Portal. I still stick with PowerShell, even though I primarily use a Mac computer for development work. (I’ll talk more about this in the next section.)

Deploying Your Template and Parameter File

To deploy your ARM template to Azure, follow the instructions provided here. Take note on the different ways you can deploy a template, specifically how to pass in template parameters as a local or external parameter file. I’ll summarize these below:

  1. Login to your Azure account / subscription – this will prompt you with an interactive login: For Azure Gov (if you are using Azure Government Cloud for the target could platform):
    Add-AzureRmAccount -EnvironmentName AzureUSGovernment For Azure Commercial:
  2. Create a resource group:
    New-AzureRmResourceGroup -Name ExampleResourceGroup -Location "West US"
    New-AzureRmResourceGroup -Name ExampleResourceGroup -Location " USGov Virginia"(A resource group is simply a container that will hold your Azure resources. Having a resource group is especially useful if you want to delete an entire networking infrastructure instead of having to delete each of your resources one by one.)
  3. Deploy template to resource group: Deploy using a local template and parameter file
    New-AzureRmResourceGroupDeployment -Name ExampleDeployment -ResourceGroupName ExampleResourceGroup -TemplateFile c:\MyTemplates\example.json -TemplateParameterFile c:\MyTemplates\example.params.jsonDeploy with a local template file and inline parameters
    New-AzureRmResourceGroupDeployment -Name ExampleDeployment -ResourceGroupName ExampleResourceGroup -TemplateFile <PathToTemplate> -myParameterName "parameterValue" Deploy with an external template and parameter file
    New-AzureRmResourceGroupDeployment -Name ExampleDeployment -ResourceGroupName ExampleResourceGroup -TemplateUri <LinkToTemplate> -TemplateParameterUri https://raw.githubusercontent.com/exampleuser/MyTemplates/master/example.params.json

The parameter file mentioned in the steps above is just another JSON template file that contains the name and value of the parameter you want to deploy your template with. Check out Azure’s Github page for quick start templates to see examples of these parameter files.

Let’s focus on that last method of deploying our infrastructure with an externally-linked template and parameter template. This is important because this consolidates our deployment configuration to a single file of parameters. This gives us some flexibility if we want to deploy several environments of the same infrastructure with different configurations. The other alternative would be to use inline parameters. However, with more complex infrastructure patterns, using inline parameters make your scripts less readable and harder to execute because of the large number of parameters involved.

In the final part of the series, we will go over how to use an Azure Automation Account with Octopus Deploy to fully automate and organize your deployment pipeline.