Resource deployment using ARM template from the Powershell
We have completed how to deploy a virtual machine from the PowerShell, here we will learn how to deploy resource using ARM template with the Powershell commands.
The ARM template is a JSON file contains all the detail required to deploy a resource. Here we will use an ARM template that contains details about deploying a Storge account.
Create a file named storage.json with “vi” editor and add the below content.
{ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "storageAccountType": { "type": "string", "defaultValue": "Standard_LRS", "allowedValues": [ "Standard_LRS", "Standard_GRS", "Standard_ZRS", "Premium_LRS" ], "metadata": { "description": "Types of storage accounts" } }, "location": { "type": "string", "defaultValue": "[resourceGroup().location]", "metadata": { "description": "Location for all resources." } } }, "variables": { "storageAccountName": "techiesarmstorage" }, "resources": [ { "type": "Microsoft.Storage/storageAccounts", "name": "[variables('storageAccountName')]", "location": "[parameters('location')]", "apiVersion": "2019-04-01", "sku": { "name": "[parameters('storageAccountType')]" }, "kind": "StorageV2", "properties": {} } ], "outputs": { "storageAccountName": { "type": "string", "value": "[variables('storageAccountName')]" } } }
We have the ARM template ready, in this template, I have added a name for our storage account which is “techiesarmstorage”, next execute below command to deploy it.
PS /home/techies> New-AzResourceGroupDeployment ` >> -Name armdeployment ` >> -ResourceGroupName Techies_DevOps ` >> -TemplateFile ./storage.json
The “New-AzResourceGroupDeployment” command is used for the ARM template deployment and the “-Name” argument is the name for the deployment. (This is not the name of storage account)
We can see the deployment status under the Resource Group -> Overview -> Deployments section.
Once the deployment is completed, a few details about the resource will be printed in the terminal.
Here the provisioning state is ‘success’, it means we have successfully deployed a resource using the ARM template from the Powershell.