Azure 資源提供者和類型 \(部分機器翻譯\)

Azure 資源提供者是一組 REST 作業,可啟用特定 Azure 服務的功能。 例如,金鑰保存庫服務是由名為 Microsoft.KeyVault 的資源提供者所組成的。 資源提供者會定義 REST 作業,以便管理保存庫、祕密、金鑰和憑證。

資源提供者會定義您可以部署到帳戶的 Azure 資源。 資源類型的名稱會遵循下列格式:{resource-provider}/{resource-type}。 金鑰保存庫的資源類型是 Microsoft.KeyVault/vaults

在本文中,您將學會如何:

  • 在 Azure 中檢視所有資源提供者
  • 檢查資源提供者的註冊狀態
  • 註冊資源提供者
  • 檢視資源提供者的資源類型
  • 檢視資源類型的有效位置
  • 檢視資源類型的有效 API 版本

如需將資源提供者對應至 Azure 服務的清單,請參閱 Azure 服務的資源提供者

註冊資源提供者

使用資源提供者之前,您必須確定已向資源提供者註冊您的 Azure 訂用帳戶。 註冊可將您的訂用帳戶設定為可搭配資源提供者使用。

重要

只有在您準備好使用資源提供者時,才需加以註冊。 此註冊步驟有助於在訂用帳戶內維持最低權限。 惡意用戶無法使用未註冊的資源提供者。

註冊非必要的資源提供者可能會導致無法辨識的應用程式出現在您的 Microsoft Entra 租用戶中。 註冊資源提供者時,Microsoft 即會新增資源提供者的應用程式。 這些應用程式通常是由 Windows Azure 服務管理 API 負責新增。 若要防止租用戶中出現非必要的應用程式,請僅註冊所需的資源提供者。

預設會註冊某些資源提供者。 如需依預設註冊的資源提供者清單,請參閱 Azure 服務的資源提供者

其他資源提供者則會在您採取特定動作時自動註冊。 當您透過入口網站建立資源時,通常會為您註冊資源提供者。 在您部署 Azure Resource Manager 範本或 Bicep 檔案時,即會自動註冊範本中所定義的資源提供者。 有時候,範本中的資源會需要模板中所沒有的支援資源。 常見的範例包括監視或安全性資源。 此時您必須手動註冊這些資源提供者。

若是其他情況,您可能需要手動註冊資源提供者。

重要

針對處於註冊中狀態的資源提供者,您的應用程式程式碼不應封鎖資源的建立。 在您註冊資源提供者時,系統會針對每個支援的區域個別執行此作業。 若要在區域中建立資源,只需在該區域中完成註冊。 如果不封鎖處於註冊中狀態的資源提供者,您的應用程式便無需等候所有區域完成,而能以更快的速度繼續執行。

您必須擁有對資源提供者執行 /register/action 作業的權限。 權限包括在「參與者」和「擁有者」角色中。

如果您的訂用帳戶中仍有來自資源提供者的資源類型,則無法將該資源提供者取消註冊。

資源提供者支援您需要使用的新位置時,請重新註冊資源提供者。

Azure 入口網站

註冊資源提供者

若要查看所有資源提供者,以及您訂用帳戶的登錄狀態:

  1. 登入 Azure 入口網站

  2. 在 Azure 入口網站功能表上,搜尋訂用帳戶。 從可用的選項中進行選取。

    Screenshot of searching for subscriptions in the Azure portal.

  3. 選取您要檢視的訂用帳戶。

    Screenshot of selecting a subscription in the Azure portal.

  4. 在左側功能表的 [設定] 下,選取 [資源提供者] 。

    Screenshot of selecting resource providers in the Azure portal.

  5. 尋找您要註冊的資源提供者,然後選取 [註冊]。 為維護訂用帳戶中的最小權限,請只註冊您已經準備使用的資源提供者。

    Screenshot of registering a resource provider in the Azure portal.

    重要

    先前所述,針對處於註冊中狀態的資源提供者,請勿封鎖資源的建立。 如果不封鎖處於註冊中狀態的資源提供者,您的應用程式便無需等候所有區域完成,而能以更快的速度繼續執行。

  6. 重新註冊資源提供者,以使用自先前註冊之後所新增的位置。

    Screenshot of reregistering a resource provider in the Azure portal.

檢視資源提供者

若要查看特定資源提供者的資訊:

  1. 登入 Azure 入口網站

  2. 在 Azure 入口網站功能表上,選取 [所有服務]

  3. 在 [所有服務] 方塊中,輸入 [資源總管],然後選取 [資源總管]

    Screenshot of selecting All services in the Azure portal to access Resource Explorer.

  4. 選取向右箭號可展開 [提供者]

    Screenshot of expanding the Providers section in the Azure Resource Explorer.

  5. 展開資源提供者和您想要檢視的資源類型。

    Screenshot of expanding a resource provider and resource type in the Azure Resource Explorer.

  6. 所有區域都支援資源管理員,但您部署的資源可能無法在所有區域中受到支援。 此外,您的訂用帳戶上可能會有一些限制,讓您無法使用某些支援該資源的區域。 資源總管會顯示資源類型的有效位置。

    Screenshot of displaying valid locations for a resource type in the Azure Resource Explorer.

  7. API 版本會對應至資源提供者的 REST API 作業版本。 當資源提供者啟用新功能時,它會發行新版本的 REST API。 資源總管會顯示資源類型的有效 API 版本。

    Screenshot of displaying valid API versions for a resource type in the Azure Resource Explorer.

Azure PowerShell

若要查看 Azure 中的所有資源提供者,以及您訂用帳戶的登錄狀態,請使用:

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

此命令會傳回:

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

若要查看您訂用帳戶的所有已註冊資源提供者,請使用:

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

為維護訂用帳戶中的最小權限,請只註冊您已經準備使用的資源提供者。 若要註冊資源提供者,請使用:

Register-AzResourceProvider -ProviderNamespace Microsoft.Batch

此命令會傳回:

ProviderNamespace : Microsoft.Batch
RegistrationState : Registering
ResourceTypes     : {batchAccounts, operations, locations, locations/quotas}
Locations         : {West Europe, East US, East US 2, West US...}

重要

先前所述,針對處於註冊中狀態的資源提供者,請勿封鎖資源的建立。 如果不封鎖處於註冊中狀態的資源提供者,您的應用程式便無需等候所有區域完成,而能以更快的速度繼續執行。

重新註冊資源提供者,以使用自先前註冊之後所新增的位置。 若要重新註冊,請再次執行註冊命令。

若要查看特定資源提供者的資訊,請使用:

Get-AzResourceProvider -ProviderNamespace Microsoft.Batch

此命令會傳回:

{ProviderNamespace : Microsoft.Batch
RegistrationState : Registered
ResourceTypes     : {batchAccounts}
Locations         : {West Europe, East US, East US 2, West US...}

...

若要查看資源提供者的資源類型,請使用:

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

此命令會傳回:

batchAccounts
operations
locations
locations/quotas

API 版本會對應至資源提供者的 REST API 作業版本。 當資源提供者啟用新功能時,它會發行新版本的 REST API。

若要取得資源類型的可用 API 版本,請使用:

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

此命令會傳回:

2023-05-01
2022-10-01
2022-06-01
2022-01-01
2021-06-01
2021-01-01
...

所有區域都支援資源管理員,但您部署的資源可能無法在所有區域中受到支援。 此外,您的訂用帳戶上可能會有一些限制,讓您無法使用某些支援該資源的區域。

若要取得資源類型支援的位置,請使用:

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

此命令會傳回:

West Europe
East US
East US 2
West US
...

Azure CLI

若要查看 Azure 中的所有資源提供者,以及您訂用帳戶的登錄狀態,請使用:

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

此命令會傳回:

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

若要查看您訂用帳戶的所有已註冊資源提供者,請使用:

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

為維護訂用帳戶中的最小權限,請只註冊您已經準備使用的資源提供者。 若要註冊資源提供者,請使用:

az provider register --namespace Microsoft.Batch

此命令會傳回註冊持續進行中的訊息。

若要查看特定資源提供者的資訊,請使用:

az provider show --namespace Microsoft.Batch

此命令會傳回:

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

重要

先前所述,針對處於註冊中狀態的資源提供者,請勿封鎖資源的建立。 如果不封鎖處於註冊中狀態的資源提供者,您的應用程式便無需等候所有區域完成,而能以更快的速度繼續執行。

若要查看資源提供者的資源類型,請使用:

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

此命令會傳回:

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

API 版本會對應至資源提供者的 REST API 作業版本。 當資源提供者啟用新功能時,它會發行新版本的 REST API。

若要取得資源類型的可用 API 版本,請使用:

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

此命令會傳回:

Result
---------------
2023-05-01
2022-10-01
2022-06-01
2022-01-01
...

所有區域都支援資源管理員,但您部署的資源可能無法在所有區域中受到支援。 此外,您的訂用帳戶上可能會有一些限制,讓您無法使用某些支援該資源的區域。

若要取得資源類型支援的位置,請使用:

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

此命令會傳回:

Result
---------------
West Europe
East US
East US 2
West US
...

Python

若要查看 Azure 中的所有資源提供者,以及您訂用帳戶的登錄狀態,請使用:

import os  
from azure.identity import DefaultAzureCredential  
from azure.mgmt.resource import ResourceManagementClient  
  
# Authentication  
credential = DefaultAzureCredential()  
subscription_id = os.environ["AZURE_SUBSCRIPTION_ID"]  
  
# Initialize Resource Management client  
resource_management_client = ResourceManagementClient(credential, subscription_id)  
  
# List available resource providers and select ProviderNamespace and RegistrationState  
providers = resource_management_client.providers.list()  
  
for provider in providers:  
    print(f"ProviderNamespace: {provider.namespace}, RegistrationState: {provider.registration_state}")  

此命令會傳回:

ProviderNamespace: Microsoft.AlertsManagement, RegistrationState: Registered
ProviderNamespace: Microsoft.AnalysisServices, RegistrationState: Registered
ProviderNamespace: Microsoft.ApiManagement, RegistrationState: Registered
ProviderNamespace: Microsoft.Authorization, RegistrationState: Registered
ProviderNamespace: Microsoft.Batch, RegistrationState: Registered
...

若要查看您訂用帳戶的所有已註冊資源提供者,請使用:

# List available resource providers with RegistrationState "Registered" and select ProviderNamespace and RegistrationState  
providers = resource_management_client.providers.list()  
registered_providers = [provider for provider in providers if provider.registration_state == "Registered"]  
  
# Sort by ProviderNamespace  
sorted_registered_providers = sorted(registered_providers, key=lambda x: x.namespace)  
  
for provider in sorted_registered_providers:  
    print(f"ProviderNamespace: {provider.namespace}, RegistrationState: {provider.registration_state}")  

為維護訂用帳戶中的最小權限,請只註冊您已經準備使用的資源提供者。 若要註冊資源提供者,請使用:

import os  
from azure.identity import DefaultAzureCredential  
from azure.mgmt.resource import ResourceManagementClient  
  
# Authentication  
credential = DefaultAzureCredential()  
subscription_id = os.environ["AZURE_SUBSCRIPTION_ID"]  
  
# Initialize Resource Management client  
resource_management_client = ResourceManagementClient(credential, subscription_id)  
  
# Register resource provider  
provider_namespace = "Microsoft.Batch"  
registration_result = resource_management_client.providers.register(provider_namespace)  
  
print(f"ProviderNamespace: {registration_result.namespace}, RegistrationState: {registration_result.registration_state}")  

此命令會傳回:

ProviderNamespace: Microsoft.Batch, RegistrationState: Registered

重要

先前所述,針對處於註冊中狀態的資源提供者,請勿封鎖資源的建立。 如果不封鎖處於註冊中狀態的資源提供者,您的應用程式便無需等候所有區域完成,而能以更快的速度繼續執行。

重新註冊資源提供者,以使用自先前註冊之後所新增的位置。 若要重新註冊,請再次執行註冊命令。

若要查看特定資源提供者的資訊,請使用:

import os  
from azure.identity import DefaultAzureCredential  
from azure.mgmt.resource import ResourceManagementClient  
  
# Authentication  
credential = DefaultAzureCredential()  
subscription_id = os.environ["AZURE_SUBSCRIPTION_ID"]  
  
# Initialize Resource Management client  
resource_management_client = ResourceManagementClient(credential, subscription_id)  
  
# Get resource provider by ProviderNamespace  
provider_namespace = "Microsoft.Batch"  
provider = resource_management_client.providers.get(provider_namespace)  
  
print(f"ProviderNamespace: {provider.namespace}, RegistrationState: {provider.registration_state}\n")  
  
# Add resource types, locations, and API versions with new lines to separate results  
for resource_type in provider.resource_types:  
    print(f"ResourceType: {resource_type.resource_type}\nLocations: {', '.join(resource_type.locations)}\nAPIVersions: {', '.join(resource_type.api_versions)}\n")  

此命令會傳回:

ProviderNamespace: Microsoft.Batch, RegistrationState: Registered

ResourceType: batchAccounts
Locations: West Europe, East US, East US 2, West US, North Central US, Brazil South, North Europe, Central US, East Asia, Japan East, Australia Southeast, Japan West, Korea South, Korea Central, Southeast Asia, South Central US, Australia East, Jio India West, South India, Central India, West India, Canada Central, Canada East, UK South, UK West, West Central US, West US 2, France Central, South Africa North, UAE North, Australia Central, Germany West Central, Switzerland North, Norway East, Brazil Southeast, West US 3, Sweden Central, Qatar Central, Poland Central, East US 2 EUAP, Central US EUAP
APIVersions: 2023-05-01, 2022-10-01, 2022-06-01, 2022-01-01, 2021-06-01, 2021-01-01, 2020-09-01, 2020-05-01, 2020-03-01-preview, 2020-03-01, 2019-08-01, 2019-04-01, 2018-12-01, 2017-09-01, 2017-05-01, 2017-01-01, 2015-12-01, 2015-09-01, 2015-07-01, 2014-05-01-privatepreview

...

若要查看資源提供者的資源類型,請使用:

# Get resource provider by ProviderNamespace  
provider_namespace = "Microsoft.Batch"  
provider = resource_management_client.providers.get(provider_namespace)  
  
# Get ResourceTypeName of the resource types  
resource_type_names = [resource_type.resource_type for resource_type in provider.resource_types]  
  
for resource_type_name in resource_type_names:  
    print(resource_type_name)  

此命令會傳回:

batchAccounts
batchAccounts/pools
batchAccounts/detectors
batchAccounts/certificates
operations
locations
locations/quotas
locations/checkNameAvailability
locations/accountOperationResults
locations/virtualMachineSkus
locations/cloudServiceSkus

API 版本會對應至資源提供者的 REST API 作業版本。 當資源提供者啟用新功能時,它會發行新版本的 REST API。

若要取得資源類型的可用 API 版本,請使用:

# Get resource provider by ProviderNamespace  
provider_namespace = "Microsoft.Batch"  
provider = resource_management_client.providers.get(provider_namespace)  
  
# Filter resource type by ResourceTypeName and get its ApiVersions  
resource_type_name = "batchAccounts"  
api_versions = [  
    resource_type.api_versions  
    for resource_type in provider.resource_types  
    if resource_type.resource_type == resource_type_name  
]  
  
for api_version in api_versions[0]:  
    print(api_version)  

此命令會傳回:

2023-05-01
2022-10-01
2022-06-01
2022-01-01
...

所有區域都支援資源管理員,但您部署的資源可能無法在所有區域中受到支援。 此外,您的訂用帳戶上可能會有一些限制,讓您無法使用某些支援該資源的區域。

若要取得資源類型支援的位置,請使用:

# Get resource provider by ProviderNamespace  
provider_namespace = "Microsoft.Batch"  
provider = resource_management_client.providers.get(provider_namespace)  
  
# Filter resource type by ResourceTypeName and get its Locations  
resource_type_name = "batchAccounts"  
locations = [  
    resource_type.locations  
    for resource_type in provider.resource_types  
    if resource_type.resource_type == resource_type_name  
]  
  
for location in locations[0]:  
    print(location)  

此命令會傳回:

West Europe
East US
East US 2
West US
...

下一步