I have an Azure generated template and parameters file for creating a simple VM. It works fine with the supplied deploy.ps1. I've updated the parameters file to create another VM in a new resource group, but it now fails with an "Invalid resource reference" error.
I've reviewed the template, but not changed it. I can see there's nothing hard-coded. The deployment creates the Network Security Group and the public IP address but then fails on the NIC. I've checked for region issues, but can't see any.
The NIC part of the template looks like this:
"variables": {
"nsgId": "[resourceId(resourceGroup().name, 'Microsoft.Network/networkSecurityGroups', parameters('networkSecurityGroupName'))]",
"vnetId": "[parameters('virtualNetworkId')]",
"subnetRef": "[concat(variables('vnetId'), '/subnets/', parameters('subnetName'))]"
},
"resources": [
{
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2018-10-01",
"name": "[parameters('networkInterfaceName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/networkSecurityGroups/', parameters('networkSecurityGroupName'))]",
"[concat('Microsoft.Network/publicIpAddresses/', parameters('publicIpAddressName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"subnet": {
"id": "[variables('subnetRef')]"
},
"privateIPAllocationMethod": "Dynamic",
"publicIpAddress": {
"id": "[resourceId(resourceGroup().name, 'Microsoft.Network/publicIpAddresses', parameters('publicIpAddressName'))]"
}
}
}
],
"networkSecurityGroup": {
"id": "[variables('nsgId')]"
}
}
},
The error message is:
New-AzResourceGroupDeployment : 17:11:30 - Resource Microsoft.Network/networkInterfaces 'newRHserverNIC' failed with message '{ "error": { "code": "InvalidResourceReference", "message": "Resource /subscriptions//resourceGroups/Scripttest2/providers/Microsoft.Network/virtualNetworks/NewvirtNet/subnets/default referenced by resource /subscriptions//resourceGroups/Scripttest2/providers/Microsoft.Network/networkInterfaces/newRHserverNIC was not found. Please make sure that the referenced resource exists, and that both resources are in the same region.", "details": [] } }'