尝试为 API arm 模板设置诊断设置

时间:2021-04-12 16:35:37

标签: azure azure-resource-manager

我是 ARM 模板的新手,我遇到了以下问题: 我有一个 ARM 模板,它创建了一个 API 管理服务,我希望这个 API 管理服务使用 Log Analytics 工作区,以便在那里存储它的日志。 我已经创建了一个日志分析工作区资源。

因此,根据 Microsoft 文档:https://docs.microsoft.com/en-us/azure/azure-monitor/essentials/resource-manager-diagnostic-settings 我唯一需要做的就是编辑 API 管理 ARM 模板并包含一个新资源: "type": "Microsoft.Insights/diagnosticSettings"

但是当我这样做时,我收到以下错误: “值必须是以下值之一......”得到一个长长的列表。

我在这里做错了吗?

感谢您的时间!

1 个答案:

答案 0 :(得分:0)

如果我们想为 Azure API 管理资源创建诊断设置,我们可以将 Microsoft.ApiManagement/service/providers/diagnosticSettings 类型的资源添加到模板中。

例如

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "publisherEmail": {
            "type": "string",
            "minLength": 1,
            "metadata": {
                "description": "The email address of the owner of the service"
            },
            "defaultValue": "test@gmail.com"
        },
        "publisherName": {
            "type": "string",
            "minLength": 1,
            "metadata": {
                "description": "The name of the owner of the service"
            },
            "defaultValue": "test",
        },
        "sku": {
            "type": "string",
            "defaultValue": "Developer",
            "allowedValues": [
                "Developer",
                "Standard",
                "Premium"
            ],
            "metadata": {
                "description": "The pricing tier of this API Management service"
            }
        },
        "skuCount": {
            "type": "string",
            "defaultValue": "1",
            "allowedValues": [
                "1",
                "2"
            ],
            "metadata": {
                "description": "The instance size of this API Management service."
            }
        },
        "location": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]",
            "metadata": {
                "description": "Location for all resources."
            }
        }
    },
    "variables": {
        "apiManagementServiceName": "[concat('myapiservice', uniqueString(resourceGroup().id))]"
    },
    "resources": [{
            "type": "Microsoft.ApiManagement/service",
            "apiVersion": "2019-12-01",
            "name": "[variables('apiManagementServiceName')]",
            "location": "[parameters('location')]",
            "sku": {
                "name": "[parameters('sku')]",
                "capacity": "[parameters('skuCount')]"
            },
            "properties": {
                "publisherEmail": "[parameters('publisherEmail')]",
                "publisherName": "[parameters('publisherName')]"
            }
        }, {
            "type": "Microsoft.ApiManagement/service/providers/diagnosticSettings",
            "apiVersion": "2017-05-01-preview",
            "name": "[concat(variables('apiManagementServiceName'), '/Microsoft.Insights/', 'mytest')]",
            "dependsOn": ["[resourceId('Microsoft.ApiManagement/service', variables('apiManagementServiceName'))]"],
            "properties": {
                "logs": [{
                        "category": "GatewayLogs",
                        "enabled": true,

                    }
                ],
                "metrics": [{
                        "enabled": true,

                        "category": "AllMetrics"
                    }
                ],
                "workspaceId": "<the resource id of workspace>",

            }
        }
    ]
}

enter image description here