Deploy ARM template – PowerShell

Azure PowerShell can be used to deploy resources to Azure using ARM templates.

Prerequisites

  • A template to deploy. This can either be stored locally or on a remote source control repository (such as GitHub)
  • Azure PowerShell module installed (see post)
  • Connected to Azure by using Connect-AzAccount  (see post)

Deploy a Locally stored Template

The following example creates a resource group, and deploys a template from your local machine.

$resourceGroupName = Read-Host -Prompt “Enter the Resource Group name”
$location = Read-Host -Prompt “Enter the location (i.e. centralus)”

New-AzResourceGroup -Name $resourceGroupName -Location $location
New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName `
-TemplateFile c:\MyTemplates\azuredeploy.json

The first two lines requests an input to create the resource group name and location.  The next line New-AzResourceGroup creates the resource group with the specified name and location.

New-AzResourveGroupDeployment is the command that takes the locally stored template “c:MyTemplates\azuredeploy.json” and deploys it to Azure.

 

Deploy a Remote Template

Templates stored on source control repository (such as GitHub)or an Azure storage account, can be used for deployment. To deploy an external template, use the TemplateUri parameter. Use the URI in the example to deploy the sample template from GitHub.

$resourceGroupName = Read-Host -Prompt “Enter the Resource Group name”
$location = Read-Host -Prompt “Enter the location (i.e. centralus)”

New-AzResourceGroup -Name $resourceGroupName -Location $location
New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName `
-TemplateUri https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-storage-account-create/azuredeploy.json

Leave a Reply