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, you must register the resource provider for your Azure subscription. 此步骤配置你的订阅,使之与资源提供程序配合工作。This step configures your subscription to work with the resource provider. 注册的作用域始终是订阅。The scope for registration is always the subscription. 默认情况下,将自动注册许多资源提供程序。By default, many resource providers are automatically registered. 但可能需要手动注册某些资源提供程序。However, you may need to manually register some resource providers.

本文介绍了如何检查资源提供程序的注册状态,并根据需要将其注册。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.

你的应用程序代码不应阻止为处于“正在注册”状态的资源提供程序创建资源的操作。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

查看所有资源提供程序和订阅的注册状态: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, select All services.

    选择订阅

  3. 在“所有服务” 框中,输入“订阅” ,然后选择“订阅” 。In the All services box, enter subscription, and then select Subscriptions.

  4. 从订阅列表中选择订阅进行查看。Select the subscription from the subscription list to view.

  5. 选择“资源提供程序” 并查看可用资源提供程序的列表。Select Resource providers and view the list of available resource providers.

    选择订阅

  6. 若要注册资源提供程序,请选择“注册” 。To register a resource provider, select Register. 在上一屏幕截图中,针对 Microsoft.Batch 突出显示了“注册”链接。In the previous screenshot, the Register link is highlighted for Microsoft.Batch.

查看特定资源提供程序的信息: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.

    选择订阅

Azure PowerShellAzure PowerShell

备注

本文进行了更新,以便使用新的 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.

若要查看 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 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 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