解决资源提供程序注册的错误Resolve errors for resource provider registration

本文介绍使用之前未在订阅中使用过的资源提供程序时可能遇到的错误。This article describes the errors you may encounter when using a resource provider that you haven't previously used in your subscription.

备注

本文进行了更新,以便使用新的 Azure PowerShell Az 模块。This article has been updated to use the new Azure PowerShell Az module. 你仍然可以使用 AzureRM 模块,至少在 2020 年 12 月之前,它将继续接收 bug 修补程序。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 若要详细了解新的 Az 模块和 AzureRM 兼容性,请参阅新 Azure Powershell Az 模块简介To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. 有关 Az 模块安装说明,请参阅安装 Azure PowerShellFor Az module installation instructions, see Install Azure PowerShell.

症状Symptom

部署资源时,可能会收到以下错误代码和消息:When deploying resource, you may receive the following error code and message:

Code: NoRegisteredProviderFound
Message: No registered resource provider found for location {location}
and API version {api-version} for type {resource-type}.

或者,可能收到类似的消息,指出:Or, you may receive a similar message that states:

Code: MissingSubscriptionRegistration
Message: The subscription is not registered to use namespace {resource-provider-namespace}

错误消息应提供有关支持的位置和 API 版本的建议。The error message should give you suggestions for the supported locations and API versions. 可以将模板更改为建议的值之一。You can change your template to one of the suggested values. Azure 门户或正在使用的命令行接口会自动注册大多数提供程序;但非全部。Most providers are registered automatically by the Azure portal or the command-line interface you're using, but not all. 如果以前未使用特定的资源提供程序,则可能需要注册该提供程序。If you haven't used a particular resource provider before, you may need to register that provider.

或者,禁用虚拟机的自动关闭功能时,可能会收到类似如下的错误消息:Or, when disabling auto-shutdown for virtual machines, you may receive an error message similar to:

Code: AuthorizationFailed
Message: The client '<identifier>' with object id '<identifier>' does not have authorization to perform action 'Microsoft.Compute/virtualMachines/read' over scope ...

原因Cause

可能会由于以下原因之一而收到这些错误:You receive these errors for one of these reasons:

  • 尚未为订阅注册所需的资源提供程序The required resource provider hasn't been registered for your subscription
  • 资源类型不支持该 API 版本API version not supported for the resource type
  • 资源类型不支持该位置Location not supported for the resource type
  • 对于 VM 的自动关闭,必须注册 Microsoft.DevTestLab 资源提供程序。For auto-shutdown of VMs, the Microsoft.DevTestLab resource provider must be registered.

解决方案 1 - PowerShellSolution 1 - PowerShell

对于 PowerShell,请使用 Get-AzResourceProvider 查看注册状态 。For PowerShell, use Get-AzResourceProvider to see your registration status.

Get-AzResourceProvider -ListAvailable

若要注册提供程序,请使用 Register-AzResourceProvider,并提供想要注册的资源提供程序的名称。To register a provider, use Register-AzResourceProvider and provide the name of the resource provider you wish to register.

Register-AzResourceProvider -ProviderNamespace Microsoft.Cdn

若要获取特定类型的资源支持的位置,请使用:To get the supported locations for a particular type of resource, use:

((Get-AzResourceProvider -ProviderNamespace Microsoft.Web).ResourceTypes | Where-Object ResourceTypeName -eq sites).Locations

若要获取特定类型的资源支持的 API 版本,请使用:To get the supported API versions for a particular type of resource, use:

((Get-AzResourceProvider -ProviderNamespace Microsoft.Web).ResourceTypes | Where-Object ResourceTypeName -eq sites).ApiVersions

解决方案 2 - Azure CLISolution 2 - Azure CLI

若要查看是否已注册提供程序,请使用 az provider list 命令。To see whether the provider is registered, use the az provider list command.

az provider list

若要注册资源提供程序,请使用 az provider register 命令,并指定要注册的命名空间To register a resource provider, use the az provider register command, and specify the namespace to register.

az provider register --namespace Microsoft.Cdn

若要查看支持用于某个资源类型的位置和 API 版本,请使用:To see the supported locations and API versions for a resource type, use:

az provider show -n Microsoft.Web --query "resourceTypes[?resourceType=='sites'].locations"

解决方案 3 - Azure 门户Solution 3 - Azure portal

可以通过门户查看注册状态,并注册资源提供程序命名空间。You can see the registration status and register a resource provider namespace through the portal.

  1. 在门户中,选择“所有服务”。 From the portal, select All services.

    选择所有服务

  2. 选择 订阅Select Subscriptions.

    选择订阅

  3. 从订阅列表中,选择要用于注册资源提供程序的订阅。From the list of subscriptions, select the subscription you want to use for registering the resource provider.

    选择订阅以注册资源提供程序

  4. 对于订阅,选择“资源提供程序” 。For your subscription, select Resource providers.

    选择资源提供程序

  5. 查看资源提供程序列表,根据需要选择“注册”链接,注册尝试部署的类型的资源提供程序 。Look at the list of resource providers, and if necessary, select the Register link to register the resource provider of the type you're trying to deploy.

    列出资源提供程序