Azure 资源提供程序和类型Azure resource providers and types

部署资源时,经常需要检索有关资源提供程序和类型的信息。When deploying resources, you frequently need to retrieve information about the resource providers and types. 例如,若要存储密钥和机密,请使用 Microsoft.KeyVault 资源提供程序。For example, if you want to store keys and secrets, you work with the Microsoft.KeyVault resource provider. 此资源提供程序提供名为“保管库”的资源类型,用于创建密钥保管库。This resource provider offers a resource type called vaults for creating the key vault.

资源类型的名称采用以下格式:{resource-provider}/{resource-type} 。The name of a resource type is in the format: {resource-provider}/{resource-type}. Key Vault 的资源类型为 Microsoft.KeyVault/vaultsThe resource type for a key vault is Microsoft.KeyVault/vaults.

在本文中,学习如何:In this article, you learn how to:

  • 查看 Azure 中的所有资源提供程序View all resource providers in Azure
  • 检查资源提供程序的注册状态Check registration status of a resource provider
  • 注册资源提供程序Register a resource provider
  • 查看资源提供程序的资源类型View resource types for a resource provider
  • 查看资源类型的有效位置View valid locations for a resource type
  • 查看资源类型的有效 API 版本View valid API versions for a resource type

可以通过 Azure 门户、Azure PowerShell 或 Azure CLI 执行这些步骤。You can do these steps through the Azure portal, Azure PowerShell, or Azure CLI.

有关将资源提供程序映射到 Azure 服务的列表,请参阅 Azure 服务的资源提供程序For a list that maps resource providers to Azure services, see Resource providers for Azure services.

注册资源提供程序Register resource provider

使用资源提供程序之前,必须为资源提供程序注册 Azure 订阅。Before using a resource provider, your Azure subscription must be registered for the resource provider. 注册会配置你的订阅,使之与资源提供程序配合工作。Registration configures your subscription to work with the resource provider. 某些资源提供程序在默认情况下已注册。Some resource providers are registered by default. 当你执行某些操作时,其他资源提供程序会自动注册。Other resource providers are registered automatically when you take certain actions. 例如,当你通过门户创建资源时,系统通常会为你注册资源提供程序。For example, when you create a resource through the portal, the resource provider is typically registered for you. 对于其他方案,你可能需要手动注册资源提供程序。For other scenarios, you may need to manually register a resource provider. 有关默认情况下注册的资源提供程序的列表,请参阅 Azure 服务的资源提供程序For a list of resource providers registered by default, see Resource providers for Azure services.

本文介绍了如何检查资源提供程序的注册状态,并根据需要将其注册。This article shows you how to check the registration status of a resource provider, and register it as needed. 你必须具备为资源提供程序执行 /register/action 操作的权限。You must have permission to do the /register/action operation for the resource provider. 此权限包含在“参与者”和“所有者”角色中。The permission is included in the Contributor and Owner roles.

重要

仅在准备好使用资源提供程序时注册该程序。Only register a resource provider when you're ready to use it. 注册步骤使你能够在订阅中保留最小特权。The registration step enables you to maintain least privileges within your subscription. 恶意用户无法使用未注册的资源提供程序。A malicious user can't use resource providers that aren't registered.

你的应用程序代码不应阻止为处于“正在注册”状态的资源提供程序创建资源的操作。Your application code shouldn't block the creation of resources for a resource provider that is in the registering state. 注册资源提供程序时,将针对每个受支持的区域单独执行该操作。When you register the resource provider, the operation is done individually for each supported region. 若要在某个区域中创建资源,只需在该区域中完成注册即可。To create resources in a region, the registration only needs to be completed in that region. 如果不阻止处于正在注册状态的资源提供程序,则你的应用程序可以以快得多的速度继续执行,不需要等待所有区域完成。By not blocking resource provider in the registering state, your application can continue much sooner than waiting for all regions to complete.

当订阅中仍有某个资源提供程序的资源类型时,不能注销该资源提供程序。You can't unregister a resource provider when you still have resource types from that resource provider in your subscription.

Azure 门户Azure portal

注册资源提供程序Register resource provider

查看所有资源提供程序和订阅的注册状态:To see all resource providers, and the registration status for your subscription:

  1. 登录 Azure 门户Sign in to the Azure portal.

  2. 在 Azure 门户菜单上,搜索“订阅”。On the Azure portal menu, search for Subscriptions. 从可用选项中选择它。Select it from the available options.

    搜索订阅

  3. 选择要查看的订阅。Select the subscription you want to view.

    选择订阅

  4. 在左侧菜单中的“设置”下,选择“资源提供程序”。 On the left menu, under Settings, select Resource providers.

    选择资源提供程序

  5. 找到要注册的资源提供程序,然后选择“注册”。Find the resource provider you want to register, and select Register. 若要在订阅中保留最小特权,请仅注册准备好使用的资源提供程序。To maintain least privileges in your subscription, only register those resource providers that you're ready to use.

    注册资源提供程序

查看资源提供程序View resource provider

查看特定资源提供程序的信息:To see information for a particular resource provider:

  1. 登录 Azure 门户Sign in to the Azure portal.

  2. 在 Azure 门户菜单中,选择“所有服务” 。On the Azure portal menu, select All services.

  3. 在“所有服务” 框中,输入“资源浏览器” ,然后选择“资源浏览器” 。In the All services box, enter resource explorer, and then select Resource Explorer.

    选择“所有服务”

  4. 通过选择向右箭头来展开“提供程序” 。Expand Providers by selecting the right arrow.

    选择提供程序

  5. 展开要查看的资源提供程序和资源类型。Expand a resource provider and resource type that you want to view.

    选择资源类型

  6. 所有区域都支持 Resource Manager,但部署的资源可能无法在所有区域中受到支持。Resource Manager is supported in all regions, but the resources you deploy might not be supported in all regions. 此外,订阅可能存在一些限制,以防止用户使用某些支持该资源的区域。Also, there may be limitations on your subscription that prevent you from using some regions that support the resource. 资源浏览器显示资源类型的有效位置。The resource explorer displays valid locations for the resource type.

    显示位置

  7. API 版本对应于资源提供程序发布的 REST API 操作版本。The API version corresponds to a version of REST API operations that are released by the resource provider. 资源提供程序启用新功能时,会发布 REST API 的新版本。As a resource provider enables new features, it releases a new version of the REST API. 资源浏览器显示资源类型的有效 API 版本。The resource explorer displays valid API versions for the resource type.

    显示 API 版本

Azure PowerShellAzure PowerShell

若要查看 Azure 中的所有资源提供程序和订阅的注册状态,请使用:To see all resource providers in Azure, and the registration status for your subscription, use:

Get-AzResourceProvider -ListAvailable | Select-Object ProviderNamespace, RegistrationState

这会返回类似于以下的结果:Which returns results similar to:

ProviderNamespace                RegistrationState
-------------------------------- ------------------
Microsoft.ClassicCompute         Registered
Microsoft.ClassicNetwork         Registered
Microsoft.ClassicStorage         Registered
Microsoft.CognitiveServices      Registered
...

若要查看订阅的所有已注册资源提供程序,请使用:To see all registered resource providers for your subscription, use:

 Get-AzResourceProvider -ListAvailable | Where-Object RegistrationState -eq "Registered" | Select-Object ProviderNamespace, RegistrationState | Sort-Object ProviderNamespace

若要在订阅中保留最小特权,请仅注册准备好使用的资源提供程序。To maintain least privileges in your subscription, only register those resource providers that you're ready to use. 若要注册资源提供程序,请使用:To register a resource provider, use:

Register-AzResourceProvider -ProviderNamespace Microsoft.Batch

这会返回类似于以下的结果:Which returns results similar to:

ProviderNamespace : Microsoft.Batch
RegistrationState : Registering
ResourceTypes     : {batchAccounts, operations, locations, locations/quotas}
Locations         : {China East, China North, China East 2, China North 2}

若要查看特定资源提供程序的信息,请使用:To see information for a particular resource provider, use:

Get-AzResourceProvider -ProviderNamespace Microsoft.Batch

这会返回类似于以下的结果:Which returns results similar to:

{ProviderNamespace : Microsoft.Batch
RegistrationState : Registered
ResourceTypes     : {batchAccounts}
Locations         : {China East, China North, China East 2, China North 2}

...

若要查看资源提供程序的资源类型,请使用:To see the resource types for a resource provider, use:

(Get-AzResourceProvider -ProviderNamespace Microsoft.Batch).ResourceTypes.ResourceTypeName

将返回:Which returns:

batchAccounts
operations
locations
locations/quotas

API 版本对应于资源提供程序发布的 REST API 操作版本。The API version corresponds to a version of REST API operations that are released by the resource provider. 资源提供程序启用新功能时,会发布 REST API 的新版本。As a resource provider enables new features, it releases a new version of the REST API.

若要获取资源类型可用的 API 版本,请使用:To get the available API versions for a resource type, use:

((Get-AzResourceProvider -ProviderNamespace Microsoft.Batch).ResourceTypes | Where-Object ResourceTypeName -eq batchAccounts).ApiVersions

将返回:Which returns:

2017-05-01
2017-01-01
2015-12-01
2015-09-01
2015-07-01

所有区域都支持 Resource Manager,但部署的资源可能无法在所有区域中受到支持。Resource Manager is supported in all regions, but the resources you deploy might not be supported in all regions. 此外,订阅可能存在一些限制,以防止用户使用某些支持该资源的区域。Also, there may be limitations on your subscription that prevent you from using some regions that support the resource.

若要获取某一资源类型的受支持位置,请使用。To get the supported locations for a resource type, use.

((Get-AzResourceProvider -ProviderNamespace Microsoft.Batch).ResourceTypes | Where-Object ResourceTypeName -eq batchAccounts).Locations

将返回:Which returns:

China East
China North
China East 2
China North 2

Azure CLIAzure CLI

若要查看 Azure 中的所有资源提供程序和订阅的注册状态,请使用:To see all resource providers in Azure, and the registration status for your subscription, use:

az provider list --query "[].{Provider:namespace, Status:registrationState}" --out table

这会返回类似于以下的结果:Which returns results similar to:

Provider                         Status
-------------------------------- ----------------
Microsoft.ClassicCompute         Registered
Microsoft.ClassicNetwork         Registered
Microsoft.ClassicStorage         Registered
Microsoft.CognitiveServices      Registered
...

若要查看订阅的所有已注册资源提供程序,请使用:To see all registered resource providers for your subscription, use:

az provider list --query "sort_by([?registrationState=='Registered'].{Provider:namespace, Status:registrationState}, &Provider)" --out table

若要在订阅中保留最小特权,请仅注册准备好使用的资源提供程序。To maintain least privileges in your subscription, only register those resource providers that you're ready to use. 若要注册资源提供程序,请使用:To register a resource provider, use:

az provider register --namespace Microsoft.Batch

这将返回“注册正在进行中”的信息。Which returns a message that registration is on-going.

若要查看特定资源提供程序的信息,请使用:To see information for a particular resource provider, use:

az provider show --namespace Microsoft.Batch

这会返回类似于以下的结果:Which returns results similar to:

{
    "id": "/subscriptions/####-####/providers/Microsoft.Batch",
    "namespace": "Microsoft.Batch",
    "registrationsState": "Registering",
    "resourceTypes:" [
        ...
    ]
}

若要查看资源提供程序的资源类型,请使用:To see the resource types for a resource provider, use:

az provider show --namespace Microsoft.Batch --query "resourceTypes[*].resourceType" --out table

将返回:Which returns:

Result
---------------
batchAccounts
operations
locations
locations/quotas

API 版本对应于资源提供程序发布的 REST API 操作版本。The API version corresponds to a version of REST API operations that are released by the resource provider. 资源提供程序启用新功能时,会发布 REST API 的新版本。As a resource provider enables new features, it releases a new version of the REST API.

若要获取资源类型可用的 API 版本,请使用:To get the available API versions for a resource type, use:

az provider show --namespace Microsoft.Batch --query "resourceTypes[?resourceType=='batchAccounts'].apiVersions | [0]" --out table

将返回:Which returns:

Result
---------------
2017-05-01
2017-01-01
2015-12-01
2015-09-01
2015-07-01

所有区域都支持 Resource Manager,但部署的资源可能无法在所有区域中受到支持。Resource Manager is supported in all regions, but the resources you deploy might not be supported in all regions. 此外,订阅可能存在一些限制,以防止用户使用某些支持该资源的区域。Also, there may be limitations on your subscription that prevent you from using some regions that support the resource.

若要获取某一资源类型的受支持位置,请使用。To get the supported locations for a resource type, use.

az provider show --namespace Microsoft.Batch --query "resourceTypes[?resourceType=='batchAccounts'].locations | [0]" --out table

将返回:Which returns:

Result
---------------
China East
China North
China East 2
China North 2
...

后续步骤Next steps