我正在尝试使用模板部署 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 找不到/看到我的 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": []