5

I would like the public IP address from an App Service deployed from an ARM Template like the simplified one below. I've seen examples of getting the public inbound IP address from an API Gateway, VNET of a VM, App Service Environment, etc., but I haven't found anything that indicates how to get it out of a simple App Service deployment. I find navigating the ARM API, and how that translates into a string into a JSON file, rather byzantine. Any assistance would be appreciated.

{
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "appServiceName": {
            "type": "string",
            "minLength": 1,
            "metadata": {
                "description": "Specifies the name of the Azure App Service"
            }
        },
        "appServicePlanName": {
            "type": "string",
            "minLength": 1
        }
    },
    "variables": {
    },
    "resources": [
        {
            "apiVersion": "2015-08-01",
            "name": "[parameters('appServiceName')]",
            "type": "Microsoft.Web/sites",
            "kind": "app",
            "location": "[resourceGroup().location]",
            "dependsOn": [],
            "properties": {
                "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]",
                "clientAffinityEnabled": false
            },
            "resources": [],
        }
    ],
    "outputs": {
        "appServiceName": {
            "type": "string",
            "value": "[parameters('appServiceName')]"
        },
        "ipAddress": {
            "type": "string",
            "value": "whatingodsnamegoeshere"
        }
    }
}
Robb Vandaveer
  • 1,481
  • 20
  • 25

1 Answers1

6

you need to use reference() function and give it resource id or just the name if the resource is in the same template:

reference(parameters('appServiceName'), '2016-03-01', 'Full').properties.inboundIpAddress

or with resourceId():

reference(resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName')), '2016-03-01', 'Full').properties.inboundIpAddress
4c74356b41
  • 69,186
  • 6
  • 100
  • 141
  • When I first read your answer it sounded "guessy" but after having outputted all the properties I see that "possibleOutboundIpAddresses" is actually a thing. Ha. Having read your answer, it suddenly occurred to me that I could output all the properties available to see what's there. So, thanks for that. I was actually looking for the `inboundIpAddress`. I just clarified the question. If you'll revise your answer in light of the edit, I'll accept it. – Robb Vandaveer Aug 18 '19 at 14:45
  • why would I post "guessy" answers? updated the answer – 4c74356b41 Aug 18 '19 at 14:59
  • ¯\_(ツ)_/¯. Accepted. – Robb Vandaveer Aug 18 '19 at 20:45
  • 2
    I made it working by referencing app service, not app service plan. – Sergey Kostrukov Sep 23 '20 at 19:50