Resolve resource not establish errors

This commodity describes the error you see when a resource tin can't be found during an operation. Typically, you run across this error when deploying resources with a Bicep file or Azure Resource Director template (ARM template). Yous as well come across this mistake when doing management tasks and Azure Resource Manager tin't discover the required resource. For case, if you endeavor to add tags to a resource that doesn't be, you receive this error.

Symptom

There are two error codes that bespeak the resource tin can't exist constitute. The NotFound error returns a result similar to:

              Lawmaking=NotFound; Message=Cannot discover ServerFarm with proper noun exampleplan.                          

The ResourceNotFound error returns a effect similar to:

              Code=ResourceNotFound; Bulletin=The Resource 'Microsoft.Storage/storageAccounts/{storage name}' nether resources group {resource group proper noun} was not found.                          

Cause

Resources Manager needs to recollect the backdrop for a resource, but can't find the resource in your subscription.

Solution ane - bank check resource properties

When you receive this error while doing a direction chore, bank check the values you provided for the resources. The three values to bank check are:

  • Resources name
  • Resource group name
  • Subscription

If you're using PowerShell or Azure CLI, bank check that y'all're running commands in the subscription that contains the resource. You can modify the subscription with Set-AzContext or az business relationship set up. Many commands provide a subscription parameter that lets you specify a dissimilar subscription than the electric current context.

If y'all can't verify the backdrop, sign in to the Microsoft Azure portal. Observe the resources you're trying to use and examine the resources name, resource group, and subscription.

Solution 2 - prepare dependencies

If yous get this error when deploying a template, you may demand to add together a dependency. Resource Manager optimizes deployments by creating resources in parallel, when possible.

For instance, when you deploy a web app, the App Service plan must exist. If you haven't specified that the web app depends on the App Service plan, Resource Manager creates both resource at the same time. The web app fails with an error that the App Service program resources tin can't be found because it doesn't exist yet. Y'all prevent this error past setting a dependency in the web app.

  • Bicep
  • JSON

Use an implicit dependency rather than the resourceId function. The dependency is created using a resource'southward symbolic proper name and ID property.

For example, the spider web app'south serverFarmId property uses servicePlan.id to create a dependency on the App Service program.

                  resources webApp 'Microsoft.Spider web/sites@2021-02-01' = {   properties: {     serverFarmId: servicePlan.id   } }  resource servicePlan 'Microsoft.Web/serverfarms@2021-02-01' = {   name: hostingPlanName   ...                                  

For most deployments, it'south not necessary to use dependsOn to create an explicit dependency.

Avoid setting dependencies that aren't needed. Unnecessary dependencies prolong the deployment's duration because resources aren't deployed in parallel. Also, yous might create circular dependencies that cake the deployment.

Deployment gild

When yous run into dependency problems, you lot need to proceeds insight into the society of resource deployment. You can employ the portal to view the order of deployment operations:

  1. Sign in to the portal.

  2. From the resource group'south Overview, select the link for the deployment history.

    Screenshot that highlights the link to a resource group's deployment history.

  3. For the Deployment proper noun you lot want to review, select Related events.

    Screenshot that highlights the link to a deployment's related events.

  4. Examine the sequence of events for each resource. Pay attention to the status of each operation and it's fourth dimension postage. For example, the following prototype shows 3 storage accounts that deployed in parallel. Discover that the three storage accounts are started at the aforementioned time.

    Screenshot of activity log for resources deployed in parallel.

    The adjacent prototype shows three storage accounts that aren't deployed in parallel. The second storage business relationship depends on the outset storage account, and the 3rd storage account depends on the second storage account. The first storage account is labeled Started, Accepted, and Succeeded before the next is started.

    Screenshot of activity log for resources deployed in sequential order.

Solution 3 - get external resource

  • Bicep
  • JSON

Bicep uses the symbolic name to create an implicit dependency on another resource. The existing keyword references a deployed resource. If an existing resource is in a different resource group than the resource you want to deploy, include scope and apply the resourceGroup function.

In this case, a web app is deployed that uses an existing App Service program from some other resource group.

                  resources servicePlan 'Microsoft.Web/serverfarms@2021-02-01' existing = {   name: hostingPlanName   telescopic: resourceGroup(rgname) }  resource webApp 'Microsoft.Web/sites@2021-02-01' = {   name: siteName   properties: {     serverFarmId: servicePlan.id   } }                                  

Solution 4 - get managed identity from resource

  • Bicep
  • JSON

If you lot're deploying a resource with a managed identity, yous must wait until that resource is deployed before retrieving values on the managed identity. Use an implicit dependency for the resource that the identity is applied to. This approach ensures the resource and the managed identity are deployed before Resources Managing director uses the dependency.

You can get the principal ID and tenant ID for a managed identity that's applied to a virtual car. For example, if a virtual machine resources has a symbolic name of vm, use the following syntax:

                  vm.identity.principalId  vm.identity.tenantId                                  

Solution 5 - check functions

  • Bicep
  • JSON

Y'all tin use a resources's symbolic name to get values from a resource. You can reference a storage account in the same resources group or another resource group using a symbolic name. To become a value from a deployed resource, use the existing keyword. If a resource is in a different resource group, utilize scope with the resourceGroup function. For almost cases, the reference function isn't needed.

The post-obit example references an existing storage account in a unlike resource grouping.

                  resource stgAcct 'Microsoft.Storage/storageAccounts@2021-06-01' existing = {   name: stgname   scope: resourceGroup(rgname) }                                  

Solution half-dozen - after deleting resource

When you delete a resources, in that location might exist a short amount of time when the resource appears in the portal but isn't available. If yous select the resource, yous'll go an fault that the resource is Not found.

Screenshot of deleted resource in portal that shows resource not found.

Refresh the portal and the deleted resource should be removed from your list of bachelor resources. If a deleted resource continues to be shown as available for more than a few minutes, contact support.