【问题标题】:Azure: How to install a specific existing site extension using ARM template?Azure:如何使用 ARM 模板安装特定的现有站点扩展?
【发布时间】:2021-10-14 12:52:48
【问题描述】:

我有一个 Azure 应用服务。我想以编程方式安装站点扩展ASP.NET Core Logging Integration

到目前为止,我所做的是:

  1. 通过 Azure 浏览器 GUI(开发工具 -> 扩展)手动安装站点扩展。
  2. 提取 ARM 模板(自动化 -> 导出模板)。
  3. 修剪 ARM 模板,使其仅包含站点和站点扩展。
  4. 通过 Azure 浏览器 GUI 删除站点扩展。
  5. 使用 CLI (az deployment group create -f template.json...) 安装 ARM 模板(到同一个应用服务)。
  6. 在 Azure 浏览器 GUI 中,验证现在是否安装了站点扩展。

以上有效。 ARM 模板正确安装站点扩展。但我不明白如何。整个模板如下所示:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "siteName": {
            "type": "string"
        },
        "location": {
            "type": "string"
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Web/sites",
            "apiVersion": "2021-01-15",
            "name": "[parameters('siteName')]",
            "location": "[parameters('location')]",
            "kind": "app",
            "properties": {}
        },
        {
            "type": "Microsoft.Web/sites/siteextensions",
            "apiVersion": "2021-01-15",
            "name": "[concat(parameters('siteName'), '/Microsoft.AspNetCore.AzureAppServices.SiteExtension')]",
            "location": "West Europe",
            "dependsOn": [
                "[resourceId('Microsoft.Web/sites', parameters('siteName'))]"
            ]
        }
    ]
}

据我所知,它没有指定要安装哪个站点扩展。所以我不明白为什么我的 ARM 模板会这样做。

谁能告诉我如何修改这个模板来安装不同的站点扩展?

【问题讨论】:

    标签: azure arm-template azure-cli


    【解决方案1】:

    以上工作。 ARM 模板正确安装站点 延期。但我不明白怎么做。

    你的答案在下面的块中:

    {
                "type": "Microsoft.Web/sites/siteextensions",
                "apiVersion": "2021-01-15",
                "name": "[concat(parameters('siteName'), '/Microsoft.AspNetCore.AzureAppServices.SiteExtension')]",
                "location": "West Europe",
                "dependsOn": [
                    "[resourceId('Microsoft.Web/sites', parameters('siteName'))]"
                ]
            }
    

    这是完成这项工作的第二个块,如下所示:

     "name": "[concat(parameters('siteName'), '/Microsoft.AspNetCore.AzureAppServices.SiteExtension')]"
    

    它由两部分组成,首先是sitename,即 webapp 名称,然后添加您要安装的站点扩展,即 Microsoft.AspNetCore.AzureAppServices.SiteExtension,这基本上是扩展的 id,正如您从 Resource Graph Explorer 中看到的那样(技术上它的 webappname /siteextensionId) 如下所示:

    subscriptions>>resourcegroups>>appresourcegroup>>providers>>Microsoft.Web>>Sites>>yourwebappname>>siteextensions
    


    如果您还想安装一些其他扩展,那么您可以在为一个应用手动安装后检查 id,如上图所示,并使用以下模板:

    {
        "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
        "contentVersion": "1.0.0.0",
        "parameters": {
            "siteName": {
                "type": "string"
            },
            "location": {
                "type": "string"
            },
            "siteextensionId": {
                "type" : "string"
            }
        },
        "variables": {},
        "resources": [
            {
                "type": "Microsoft.Web/sites",
                "apiVersion": "2021-01-15",
                "name": "[parameters('siteName')]",
                "location": "[parameters('location')]",
                "kind": "app",
                "properties": {}
            },
            {
                "type": "Microsoft.Web/sites/siteextensions",
                "apiVersion": "2021-01-15",
                "name": "[concat(parameters('siteName'),'/',parameters('siteextensionId'))]",
                "location": "West Europe",
                "dependsOn": [
                    "[resourceId('Microsoft.Web/sites', parameters('siteName'))]"
                ]
            }
        ]
    }
    

    在我的例子中,我使用了一个扩展名 .NET Retrace APM,其 id 为 Stackify.AzureWebApps

    输出:

    传送门:

    【讨论】:

    • 你是对的。我猜这些站点扩展 ID 通常非常不直观,看起来一点也不像它们的显示名称。
    猜你喜欢
    • 2017-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多