我正在尝试创建一个部署工作区和 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
}
}
]
}
]
}
我尝试了以下变体但没有成功:
我遇到的一些错误:
这就是我试图通过ARM模板实现的目标:
你需要使用这样的东西:
{
"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
}
}
]
}
}