I came across this question searching for the same error code. I had a different problem though: I was referencing child resources of another resource within the template. I guess those are considered outside of the current template.
e.g.
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.Network/virtualNetworks",
"name": "vnetName",
"location": "[resourceGroup().location]",
"apiVersion": "2018-11-01",
"properties": {
...
}
},
"resources": [
{
"type": "subnets",
"apiVersion": "2018-11-01",
"name": "subnetName",
"dependsOn": [
"[resourceId('Microsoft.Network/virtualNetworks', vnetName)]"
],
"properties": {
...
}
}
}
},
{
"apiVersion": "2016-02-01",
"name": "deploymentName",
"type": "Microsoft.Resources/deployments",
"dependsOn": [
"[resourceId('Microsoft.Network/virtualNetworks.subnets', vnetName, subnetName)]"
],
}
]
}
There the fix is to put the parent resource into a deployment and depend on that.
e.g.
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
"contentVersion": "1.0.0.0",
"resources": [
{
"apiVersion": "2016-02-01",
"name": "deployment1",
"type": "Microsoft.Resources/deployments",
"resources": [
{
"type": "Microsoft.Network/virtualNetworks",
"name": "vnetName",
"location": "[resourceGroup().location]",
"apiVersion": "2018-11-01",
"properties": {
...
},
"resources": [
{
"type": "subnets",
"apiVersion": "2018-11-01",
"name": "subnetName",
"dependsOn": [
"[resourceId('Microsoft.Network/virtualNetworks', vnetName)]"
],
"properties": {
...
}
}
]
}
]
},
{
"apiVersion": "2016-02-01",
"name": "deployment2",
"type": "Microsoft.Resources/deployments",
"dependsOn": [
"deployment1"
],
}
]
}