How to output the IP address of an App Service deployed via ARM Template

Rob*_*eer 3 azure-web-app-service azure-rm-template

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"
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

4c7*_*b41 6

reference()如果资源在同一个模板中,您需要使用函数并为其提供资源 ID 或仅提供名称:

reference(parameters('appServiceName'), '2016-03-01', 'Full').properties.inboundIpAddress
Run Code Online (Sandbox Code Playgroud)

或与resourceId()

reference(resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName')), '2016-03-01', 'Full').properties.inboundIpAddress
Run Code Online (Sandbox Code Playgroud)

  • 我通过引用应用程序服务而不是应用程序服务计划使其工作。 (2认同)