How To Create ARM Template Through Azure Portal And Deploy Using Azure PowerShell (Az)

Ahamed Fazil Buhari
 
Senior Developer
April 1, 2019
 
Rate this article
 
Views
1417

In the below context we will see how to generate Azure Resources as a template and deploy it through PowerShell. This approach greatly reduces manual work that we do to create different azure resources under particular subscription especially we when want to deploy across multiple resource group. We can either deploy to Azure Subscription by creating Resource Group then deploy other resources or we can directly deploy to Resource Group.

In the below example, I am going to deploy one of the Azure Resource – Function App service in the Resource Group.

Step 1: Creating Azure Resource Management (ARM) Template

The ARM template is nothing but a JSON file which holds schema, resources, parameters, output, and so on. This template can be created in three different ways – by using Visual Studio or VS Code or Portal,

One of the easiest ways is to create template through Portal (especially if we are not familiar with ARM template JSON file). Since it gives all the key value pair filled and only we need to change is the names if required.

After providing all the required values, click on Automation Option at the bottom of panel

Automation Option navigates to Template section where we can download the ARM template

Step 2: Deploy ARM template using Az PowerShell

Extract the template files which has been downloaded in Step 1.

I do not have AzureRm installed in my system, so I use deployment script related to Az PowerShell. If you want to migrate from AzureRm to Az please refer here. Still you can deploy using AzureRm but the command differs.

Since I am creating new Resource Group, I need to create new Resource group before deployment.

New-AzResourceGroup -Name ‘ps-deploy-test’ -Location ‘West Europe’

Once you created Resource Group (we can also skip Resource Group creation if you plan to use existing Resource Group) and run the below command –TemplateFile value should be the value which we was downloaded from Step 1.

New-AzResourceGroupDeployment -ResourceGroupName ‘ps-deploy-test’ -TemplateFile “C:\buh\me\mydata\learn\sppals\solution\ps\template\template.json”

Provide name for storage, template name (name for app service), location and Subscription ID (we can get this from Resource Group)

 

We successfully deployed ARM through Azure PowerShell (Az).

 

Happy Coding

Ahamed

Author Info

Ahamed Fazil Buhari
 
Senior Developer
 
Rate this article
 
Ahamed is a Senior Developer and he has very good experience in the field of Microsoft Technologies, especially SharePoint, Azure, M365, SPFx, .NET and client side scripting - JavaScript, TypeScript, ...read more
 

Leave a comment