Output admin URL string from azuredeploy / ARM script

1.2k Views Asked by At

I've got an azuredeploy.json that sets up an app service running my open source NodeJS web app. After the deploy runs, I'd like to output a URL to the script user (eg the person using azuredeploy.net to deploy my web app) giving them the URL of the admin console for their new server.

Some of my users have probably never used Azure before, and the hardest part of the deploy process is explaining how they find the URL of their new app service using the Azure portal (which is pretty overwhelming).

If I could output a string after the deploy it'd save them a lot of trouble.

2

There are 2 best solutions below

0
On

Have you taken a look at the output functionality within ARM templates?
See this blog for an example of how Output works and where you would see it as part of the ARM deployment in powershell.

The URL for the app service would be pretty easy to create in a variable and then just have it outputted at the end of the deployment.

0
On
{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": { ... },
  "variables": {
    ...
    "primaryWebApp": "[uniqueString(resourceGroup().id, '1')]",
    ...
  },
  "resources": [
    { ... },
    {
      "apiVersion": "2015-01-01",
      "name": "webAppPrimary",
      "type": "Microsoft.Resources/deployments",
      "dependsOn": [
        "[resourceId('Microsoft.Resources/deployments', 'StorageAccount')]"
      ],
      "properties": {
        "mode": "Incremental",
        "templateLink": { ... },
      "parameters": { 
        "siteName": {
          "value": "[variables('primaryWebApp')]"
          },
        ... }
        } 
      }
    },
    { ... }],
  "outputs": {
    "webAppPrimary": {
      "type": "string",
      "value": "[variables('primaryWebApp')]"
    },
    ...
  }
}

And then I do something like this:

try { $deploy = New-AzureRmResourceGroupDeployment @parameters }
catch { Remove-AzureRmResourceGroup -ResourceGroupName $rgName -Force; $error; exit 1 }

$primaryWepAppName = $deploy.outputs.values.value[0]

to construct the final url you would:

$url = "$primaryWebAppName.azurewebsites.net"