Part 7 – Arm Template – Use Export Template

IN our last Part 6 we used output for our template as this below  JSON:

{
 "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
 "contentVersion": "1.0.0.0",
 "parameters": {
   "storagePrefix": {
     "type": "string",
     "minLength": 3,
     "maxLength": 11
   },
   "storageSKU": {
     "type": "string",
     "defaultValue": "Standard_LRS",
     "allowedValues": [
       "Standard_LRS",
       "Standard_GRS",
       "Standard_RAGRS",
       "Standard_ZRS",
       "Premium_LRS",
       "Premium_ZRS",
       "Standard_GZRS",
       "Standard_RAGZRS"
     ]
   },
   "location": {
     "type": "string",
     "defaultValue": "[resourceGroup().location]"
   }
 },
 "variables": {
   "uniqueStorageName": "[concat(parameters('storagePrefix'), uniqueString(resourceGroup().id))]"
 },
 "resources": [
   {
     "type": "Microsoft.Storage/storageAccounts",
     "apiVersion": "2019-04-01",
     "name": "[variables('uniqueStorageName')]",
     "location": "[parameters('location')]",
     "sku": {
       "name": "[parameters('storageSKU')]"
     },
     "kind": "StorageV2",
     "properties": {
       "supportsHttpsTrafficOnly": true
     }
   }
 ],
 "outputs": {
   "storageEndpoint": {
     "type": "object",
     "value": "[reference(variables('uniqueStorageName')).primaryEndpoints]"
   }
 }
}

 

Use Export Templates

Create App Service plan

  1. Sign in to the Azure portal.
  2. Select Create a resource.
  3. In Search the Marketplace, enter App Service plan, and then select App Service plan. Don’t select App Service plan (classic)
  4. Select Create.
  5. Select Review and create.
  6. Select Create. It takes a few moments to create the resource.

Export template

  1. Select Go to resource.
  2. Select Export template.

    The export template feature takes the current state of a resource and generates a template to deploy it. Exporting a template can be a helpful way of quickly getting the JSON you need to deploy a resource.

  3. Copy the Microsoft.Web/serverfarms definition and the parameter definition to your template.

Revise existing template

{
 "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
 "contentVersion": "1.0.0.0",
 "parameters": {
   "storagePrefix": {
     "type": "string",
     "minLength": 3,
     "maxLength": 11
   },
   "storageSKU": {
     "type": "string",
     "defaultValue": "Standard_LRS",
     "allowedValues": [
       "Standard_LRS",
       "Standard_GRS",
       "Standard_RAGRS",
       "Standard_ZRS",
       "Premium_LRS",
       "Premium_ZRS",
       "Standard_GZRS",
       "Standard_RAGZRS"
     ]
   },
   "location": {
     "type": "string",
     "defaultValue": "[resourceGroup().location]"
   },
   "appServicePlanName": {
     "type": "string",
     "defaultValue": "exampleplan"
   }
 },
 "variables": {
   "uniqueStorageName": "[concat(parameters('storagePrefix'), uniqueString(resourceGroup().id))]"
 },
 "resources": [
   {
     "type": "Microsoft.Storage/storageAccounts",
     "apiVersion": "2019-04-01",
     "name": "[variables('uniqueStorageName')]",
     "location": "[parameters('location')]",
     "sku": {
       "name": "[parameters('storageSKU')]"
     },
     "kind": "StorageV2",
     "properties": {
       "supportsHttpsTrafficOnly": true
     }
   },
   {
     "type": "Microsoft.Web/serverfarms",
     "apiVersion": "2016-09-01",
     "name": "[parameters('appServicePlanName')]",
     "location": "[parameters('location')]",
     "sku": {
       "name": "B1",
       "tier": "Basic",
       "size": "B1",
       "family": "B",
       "capacity": 1
     },
     "kind": "linux",
     "properties": {
       "perSiteScaling": false,
       "reserved": true,
       "targetWorkerCount": 0,
       "targetWorkerSizeId": 0
     }
   }
 ],
 "outputs": {
   "storageEndpoint": {
     "type": "object",
     "value": "[reference(variables('uniqueStorageName')).primaryEndpoints]"
   }
 }
}

Deploy template

New-AzResourceGroupDeployment `
  -Name addappserviceplan `
  -ResourceGroupName myResourceGroup `
  -TemplateFile $templateFile `
  -storagePrefix "store" `
  -storageSKU Standard_LRS

Exit mobile version