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

时间:2018-08-02 15:15:38

标签: azure azure-virtual-machine azure-deployment azure-template

我正在尝试使用模板部署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资源存在,并且确实如此:

enter image description here

接下来,我确保将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无法找到/查看我的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": []

1 个答案:

答案 0 :(得分:1)

您可能正在部署到一个名为vmgroup的资源组,因此会出现此错误。

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

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

ps。你有两个地方。