ARM 模板中 FunctionApp 的诊断设置

问题描述 投票:0回答:1

我正在尝试创建一个部署工作区和 Azure Function App 的 ARM 模板,其中诊断设置定义为写入该工作区(而不是存储帐户)。我在门户中手动完成此操作,但正如我所说,我需要 ARM 模板。

我已经浏览了 Microsoft 文档,但没有找到此特定配置的示例(有其他资源类型的示例,但我尚未成功尝试将这些示例推断到我的用例)

我已经尝试导出完整资源组的 ARM(我创建的测试资源组,内部仅包含这些资源),但它不存在。我还尝试仅针对已创建诊断设置的 Function App 导出 ARM 模板,但再次没有提及此类设置。我看到诊断设置本身在门户中具有“查看 JSON”,我将其用作包含在我的 ARM 模板中的指南。

这是我正在使用的基本 ARM 模板(有些东西是硬编码的只是为了测试目的。一旦它起作用,我会将它们变成变量/参数)

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "variables": {
    "location": "[resourceGroup().location]",
    "hostingPlanName": "[variables('functionAppName')]",
    "storageAccountName": "[concat('sometest', variables('location'))]",
    "storageAccountType": "Standard_LRS",
    "logAnalyticsWorkspaceName": "[concat('sometest-', variables('location'), '-loganalytics')]",
    "functionAppName": "[concat('sometest-', variables('location'))]"
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "name": "[variables('storageAccountName')]",
      "apiVersion": "2022-09-01",
      "location": "[variables('location')]",
      "kind": "StorageV2",
      "sku": {
        "name": "[variables('storageAccountType')]"
      },
      "properties": {
        "supportsHttpsTrafficOnly": true
      }
    },
    {
      "type": "Microsoft.Web/serverfarms",
      "apiVersion": "2021-02-01",
      "name": "[variables('hostingPlanName')]",
      "location": "[variables('location')]",
      "sku": {
        "name": "EP2",
        "tier": "ElasticPremium",
        "size": "EP2",
        "family": "EP",
        "capacity": 1
      },
      "kind": "elastic",
      "properties": {
        "perSiteScaling": false,
        "elasticScaleEnabled": true,
        "maximumElasticWorkerCount": 100,
        "isSpot": false,
        "reserved": false,
        "isXenon": false,
        "hyperV": false,
        "targetWorkerCount": 0,
        "targetWorkerSizeId": 0,
        "zoneRedundant": false
      }
    },
    {
      "type": "Microsoft.OperationalInsights/workspaces",
      "apiVersion": "2021-12-01-preview",
      "name": "[variables('logAnalyticsWorkspaceName')]",
      "location": "[variables('location')]",
      "properties": {
        "features": {
          "enableLogAccessUsingOnlyResourcePermissions": true
        }
      }
    },
    {
      "type": "Microsoft.Web/sites",
      "apiVersion": "2018-11-01",
      "name": "[variables('functionAppName')]",
      "location": "[variables('location')]",
      "kind": "functionapp",
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
        "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
      ],
      "identity": {
        "type": "SystemAssigned"
      },
      "properties": {
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
        "httpsOnly": true,
        "http20Enabled": true,
        "use32BitWorkerProcess": false,
        "enabled": true,
        "siteConfig": {
          "functionAppScaleLimit": 100
        }
      },
      "resources": [
        {
          "type": "Microsoft.Insights/diagnosticSettings",
          "name": "aga-test-eastus-diags",
          "apiVersion": "2022-09-01",
          "dependsOn": [
            "/subscriptions/a68cb0e1-b284-49e1-9051-f8d5c6485a3d/resourcegroups/myResourceGroupName/providers/Microsoft.Web/sites/sometest-eastus",
            "/subscriptions/a68cb0e1-b284-49e1-9051-f8d5c6485a3d/resourcegroups/myResourceGroupName/providers/microsoft.operationalinsights/workspaces/sometest-eastus-loganalytics"
          ],
          "properties": {
            "workspaceId": "/subscriptions/a68cb0e1-b284-49e1-9051-f8d5c6485a3d/resourcegroups/myResourceGroupName/providers/microsoft.operationalinsights/workspaces/sometest-eastus-loganalytics",
            "logs": [
              {
                "category": "FunctionAppLogs",
                "categoryGroup": null,
                "enabled": true,
                "retentionPolicy": {
                  "days": 0,
                  "enabled": false
                }
              }
            ],
            "logAnalyticsDestinationType": null
          }
        }
      ]
    }
  ]
}

我尝试了以下变体但没有成功:

  • 在工作区中具有诊断设置
  • 在功能应用程序中具有诊断设置
  • 添加/删除 id、范围、workspaceId
  • 部署所有其他资源,然后仅使用 ARM 模板中的 DiagnosticSettings 进行新部署

我遇到的一些错误:

  • “资源类型‘/’不支持诊断设置。” => 通常通过阅读范围来解决这个问题
  • 诊断设置据说已成功部署,但没有出现在资源组资源列表中,也没有出现在工作区的诊断设置中(但如果我在诊断设置资源链接中部署完成后立即单击,则需要我进入诊断设置(有点奇怪,我不明白诊断设置本身是什么)
  • 大多数情况下,通过 ARM 模板部署时,Function App 的诊断设置菜单呈灰色,这使得甚至无法检查诊断设置是否存在,或手动创建新的设置。当我通过门户手动创建 Function App 时,不会发生这种情况(这让我认为不存在角色问题)

这就是我试图通过ARM模板实现的目标:

功能应用资源 Function App resource

诊断设置屏幕 Diagnostic settings screen

azure azure-functions azure-rm-template
1个回答
0
投票

你需要使用这样的东西:

{
    "type": "Microsoft.Web/sites/providers/diagnosticSettings",
    "name": "[concat(variables('functionAppName'), '/Microsoft.Insights/', 'aga-test-eastus-diags')]",
    "apiVersion": "2021-05-01-preview",
    "properties": {
        "workspaceId": "/subscriptions/a68cb0e1-b284-49e1-9051-f8d5c6485a3d/resourcegroups/myResourceGroupName/providers/microsoft.operationalinsights/workspaces/sometest-eastus-loganalytics",
        "logs": [
            {
                "category": "FunctionAppLogs",
                "enabled": true,
                "retentionPolicy": {
                    "days": 0,
                    "enabled": false
                }
            }
        ]
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.