Azure 资源在部署时找不到依赖关系

Azure resource can't find dependancy when deploying

我正在尝试使用模板部署 Azure Windows VM 并保持 运行 进入错误 code: InvalidResourceReference Resource X referenced by Resource Y was not found。资源 X 是 Microsoft.Network/networkSecurityGroups(名为 'FBI'),资源 Y 是 Microsoft.Network/networkInterfaces(名为 vInterface)。

我需要的所有资源都是在此部署过程中创建的,并在模板中设置了它们的依赖关系。我做的第一件事是确认我的 FBI 资源存在,它确实存在:

接下来,我确保我的 FBI 安全组在 vInterface 中被列为依赖项,以确保在创建 vInterface 之前首先创建 FBI,即:

{
        "name": "[parameters('networkInterfaceName')]",
        "type": "Microsoft.Network/networkInterfaces",
        "apiVersion": "2018-04-01",
        "location": "[parameters('location')]",
        "dependsOn": [
            "[resourceId('Microsoft.Network/publicIPAddresses', parameters('publicIpAddressName'))]",
            "[resourceId('Microsoft.Network/networkSecurityGroups', parameters('networkSecurityGroupName'))]"
        ],
        "properties": {
            "ipConfigurations": [
                {
                    "name": "ipconfig1",
                    "properties": {
                        "subnet": {
                            "id": "[variables('subnetRef')]"
                        },
                        "privateIPAllocationMethod": "Dynamic",
                        "publicIpAddress": {
                            "id": "[resourceId('VMGroup','Microsoft.Network/publicIpAddresses', parameters('publicIpAddressName'))]"
                        }
                    }
                }
            ],
            "networkSecurityGroup": {
                "id": "[resourceId('VMGroup', 'Microsoft.Network/networkSecurityGroups', parameters('networkSecurityGroupName'))]"
            }
        }
    }

我可以确认这两个资源的位置相同。一切 看起来 正常,但我不明白为什么我的 vInterface 不能 find/see 我的 FBI 安全组。

完整的错误消息供参考:

"error": {
"code": "InvalidResourceReference",
"message": "Resource /subscriptions/---/resourceGroups/VMGroup/providers/Microsoft.Network/networkSecurityGroups/FBI referenced by resource /subscriptions/---/resourceGroups/VMDeployment/providers/Microsoft.Network/networkInterfaces/vInterface was not found. Please make sure that the referenced resource exists, and that both resources are in the same region.",
"details": []

您可能正在部署到未称为 vmgroup 的资源组,因此出现此错误。

您的资源 ID 被硬编码到 vmgroup 资源组,而不是您要部署到的资源组;将您的 resourceId() 输入更改为:

"[resourceId('Microsoft.Network/networkSecurityGroups', parameters('networkSecurityGroupName'))]"

ps。你有 2 个地方。