title: Azure ARM template with PowerShell deployment fails on the NIC with an InvalidResourceReference error
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>The NIC part of the template looks like this:</p>
  
  <pre><code>"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')]"
                  }
              }
          },
  
  </code></pre>
  
  <p>The error message is:</p>
  
  <blockquote>
    <p>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": []   } }'</p>
  </blockquote>