首页 > 解决方案 > 如何输出通过 ARM 模板部署的应用服务的 IP 地址

问题描述

我想要从 ARM 模板部署的应用服务的公共 IP 地址,如下面的简化模板。我已经看到了从 API 网关、VM 的 VNET、应用服务环境等获取公共入站 IP 地址的示例,但我没有找到任何表明如何从简单的应用服务部署中获取它的内容。我发现导航 ARM API,以及它如何将字符串转换为 JSON 文件,而不是拜占庭式的。任何援助将不胜感激。

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

标签: azure-web-app-servicearm-template

解决方案


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

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

或与resourceId()

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

推荐阅读