Part 6 – Arm Template – Use OutPuts

Create OutPuts

As you saw on Part 5, we had this tempalate below:

{
 "$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
     }
   }
 ]
}

This deployment creates storage account without any information regarding storage. Sometimes we need to get return value so for that we need to add output in our template

We are using Outputs to get return values from our template.

This json files shows that it has OutPut value

{
 "$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]"
   }
 }
}

Note: The output return value is OBJECT, it returns JSON object.

The output value uses reference function to get storage account details in return. We need to pass either Name or ID of each resource. For our this deployment we will use Variable we created for our storage.

It will give us the primary endpoints property from the storage

Deploy template

 

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

In the output for the deployment command, you’ll see an object similar to:

{
    "dfs": "https://storeluktbfkpjjrkm.dfs.core.windows.net/",
    "web": "https://storeluktbfkpjjrkm.z19.web.core.windows.net/",
    "blob": "https://storeluktbfkpjjrkm.blob.core.windows.net/",
    "queue": "https://storeluktbfkpjjrkm.queue.core.windows.net/",
    "table": "https://storeluktbfkpjjrkm.table.core.windows.net/",
    "file": "https://storeluktbfkpjjrkm.file.core.windows.net/"
}

Review your work

Now, let’s look at the resource group and deployment history.

  1. Sign in to the Azure portal.
  2. select Resource groups.
  3. Select the resource group you deployed to.
  4. You should be able to see your recent Storage account being created.
  5. You should also have several successful deployments listed in the history. Select that link.
  6. You see all of your deployments in the history. Select the deployment called addoutputs.
  7. You can review the inputs.
  8. You can review the outputs.
  9. You can review the template.
Exit mobile version