找不到资源组“ <null>”下的资源“ Microsoft.Web / sites / abc-rg”

时间:2020-03-31 15:58:57

标签: azure azure-functions azure-resource-manager azure-eventgrid

functionApp已经成功部署。尝试将Azure DevOps嵌入式Powershell脚本与New-AzDeployment一起使用以部署以下ARM模板时:

{
    "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
    "contentVersion": "1.0.0.1",
    "parameters": {
        "location": {
            "type": "string",
            "defaultValue": "westus2",
            "metadata": {
                "description": "The region where resources are deployed"
            }
        },
        "functionAppName": {
            "type": "string",
            "defaultValue": "event-driven-func2",
            "metadata": {
                "description": "Func App"
            }
        },
        "eventGridSubscriptionName": {
            "type": "string",
            "defaultValue": "eventSub1",
            "metadata": {
                "description": "Name of Event Grid Subscription"
            }
        },
        "eventGridFunc":{
            "type": "string",
            "defaultValue": "VmAddedListener",
            "metadata": {
                "description" : "Function Name"
            }
        }
    },
    "variables": {
        "functionUrl" : "[concat('https://', parameters('FunctionAppName'),'.azurewebsites.net/runtime/webhooks/eventgrid?functionName=', parameters('eventGridFunc'),'&code=')]"
    },
    "resources": [
        {
            "apiVersion": "2018-01-01",
            "type": "Microsoft.EventGrid/eventSubscriptions",
            "name": "[parameters('eventGridSubscriptionName')]",
            "location": "[parameters('location')]",
            "properties": {
                "destination": {
                    "endpointType": "Webhook",
                    "properties": {
                        "endpointUrl": "[concat(variables('functionUrl'), listKeys(resourceId('Microsoft.Web/sites/host/', parameters('functionAppName'), 'default'),'2016-08-01').masterKey)]"
                    }
                },
                "filter": {
                    "subjectBeginsWith": "",
                    "subjectEndsWith": "",
                    "isSubjectCaseSensitive": false,
                    "includedEventTypes": [
                        "Microsoft.Resources.ResourceActionCancel",
                        "Microsoft.Resources.ResourceActionFailure",
                        "Microsoft.Resources.ResourceActionSuccess",
                        "Microsoft.Resources.ResourceDeleteCancel",
                        "Microsoft.Resources.ResourceDeleteFailure",
                        "Microsoft.Resources.ResourceDeleteSuccess",
                        "Microsoft.Resources.ResourceWriteCancel",
                        "Microsoft.Resources.ResourceWriteFailure",
                        "Microsoft.Resources.ResourceWriteSuccess"
                      ]
                }
            }
        }
    ],
    "outputs": {}
} 

在发行期间出现以下错误:

“错误”:{ “ code”:“ ResourceNotFound”, “ message”:“未找到资源组”下的资源'Microsoft.Web / sites / abc-rg'。” } }'

我是否需要在ARM中的某些位置指定资源组?

1 个答案:

答案 0 :(得分:0)

您要声明对ARM模板中未定义的资源的引用:listKeys(resourceId('Microsoft.Web/sites/host/', parameters('functionAppName'), 'default'),'2016-08-01').masterKey)]

resourceId仅适用于ARM模板中定义的资源。您可以通过串联和其他一些参数来构建资源ID,也可以在同一ARM模板中定义资源。

使用ARM模板时,理想的方法是在单个模板(或单个“主”模板都引用的多个模板)中定义整个环境,然后通过以下方式管理对环境的更改:相应地更新模板。