【问题标题】:The Resource 'Microsoft.Web/sites/abc-rg under resource group '<null>' was not found找不到资源组“<null>”下的资源“Microsoft.Web/sites/abc-rg”
【发布时间】:2020-07-12 06:04:12
【问题描述】:

functionApp 已经部署成功。尝试使用带有 New-AzDeployment 的 Azure DevOps 内联 powershell 脚本来部署以下 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", “消息”:“未找到资源组 '' 下的资源 'Microsoft.Web/sites/abc-rg'。” } }'

我需要在 ARM 中的某个地方指定资源组吗?

【问题讨论】:

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


    【解决方案1】:

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

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

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

    【讨论】:

      【解决方案2】:

      关于您在哪个范围内进行部署的概念,我认为这可能会导致您的麻烦。

      如果您在订阅范围内进行部署,您可以将资源部署到多个资源组中,并在部署中定义资源组。

      您始终可以修改此模板,以便在资源列表中也包含资源组的定义。您只需添加它,然后自定义以适合。

         {
            "type": "Microsoft.Resources/resourceGroups",
            "apiVersion": "2018-05-01",
            "location": "eastUs",   // your geo location
            "name": "stackOfTest",  // your desired name
            "properties": {}
          },
      

      如果您在订阅范围内进行部署,这可能会解决问题。

      但是,您可能会尝试在资源组范围内部署这些资源。这将解释错误,该错误指出模板中未定义资源组。当您在 Azure 门户的资源组级别单击“导出模板”时,您可以获得这样的模板。

      只需从您选择的 Azure 门户、PowerShell 或 dotnet 在资源组范围内创建一个新部署,您的模板就可以正常工作。

      【讨论】:

        猜你喜欢
        • 2020-06-08
        • 1970-01-01
        • 1970-01-01
        • 2020-01-26
        • 2022-12-21
        • 2020-11-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多