Azure 資源提供者和類型 \(部分機器翻譯\)
Azure 資源提供者是一組 REST 作業,可支援特定 Azure 服務的功能。 例如,Azure 金鑰保存庫 服務是由名為 Microsoft.KeyVault 的資源提供者所組成。 資源提供者會定義 REST 作業,以便管理保存庫、祕密、金鑰和憑證。
資源提供者會定義您可以部署到帳戶的 Azure 資源。 資源類型的名稱會遵循下列格式:{resource-provider}/{resource-type}。 金鑰保存庫的資源類型是 Microsoft.KeyVault/vaults。
在本文中,您將學會如何:
- 檢視 Azure 中的所有資源提供者。
- 檢查資源提供者的註冊狀態。
- 註冊資源提供者。
- 檢視資源提供者的資源類型。
- 檢視資源類型的有效位置。
- 檢視資源類型的有效 API 版本。
如需將資源提供者對應至 Azure 服務的清單,請參閱 Azure 資源提供者和類型。
註冊資源提供者
使用資源提供者之前,請確定您的 Azure 訂用帳戶已註冊給資源提供者。 註冊可將您的訂用帳戶設定為可搭配資源提供者使用。
重要
只有在您準備好使用資源提供者時,才需加以註冊。 此註冊步驟有助於在訂用帳戶內維持最低權限。 惡意用戶無法使用未註冊的資源提供者。
當您註冊資源提供者時,Microsoft為資源提供者新增應用程式。 註冊不必要的資源提供者可能會導致您無法辨識的應用程式出現在您的 Microsoft Entra 租使用者中。 Windows Azure 服務管理 API 通常會新增這些應用程式。 若要限制租使用者中不必要的應用程式,請只註冊您需要的資源提供者。
預設會註冊某些資源提供者。 如需範例清單,請參閱 Azure 服務的資源提供者。
當您採取特定動作時,Azure 會自動註冊其他資源提供者。 當您在 Azure 入口網站 中建立資源時,入口網站通常會為您註冊資源提供者。 當您部署 Azure Resource Manager 範本或 Bicep 檔案時,Azure 會自動註冊範本中定義的資源提供者。 有時候,範本中的資源會需要模板中所沒有的支援資源。 常見的範例包括監視或安全性資源。 此時您必須手動註冊這些資源提供者。
您可能需要在其他案例中手動註冊資源提供者。
重要
您的應用程式程式代碼不應該封鎖為處於註冊狀態的資源提供者建立資源。 在您註冊資源提供者時,系統會針對每個支援的區域個別執行此作業。 若要在區域中建立資源,只需在該區域中完成註冊。 當應用程式未封鎖處於註冊狀態的資源提供者時,其可以比等候所有區域完成還要快。
您必須擁有對資源提供者執行 /register/action
作業的權限。 權限包括在「參與者」和「擁有者」角色中。
如果您的訂用帳戶中仍有來自資源提供者的資源類型,則無法將該資源提供者取消註冊。
資源提供者支援您需要使用的新位置時,請重新註冊資源提供者。
Azure 入口網站
註冊資源提供者
若要查看所有資源提供者,以及您訂用帳戶的登錄狀態:
登入 Azure 入口網站。
在 Azure 入口網站功能表上,搜尋訂用帳戶。 從可用的選項中進行選取。
選取您要檢視的訂用帳戶。
在左側功能表和 [設定] 底下,選取 [資源提供者]。
尋找您想要註冊的資源提供者。
選取資源提供者以查看資源提供者的詳細資料。
依序選取資源提供者和 [註冊]。 若要在訂用帳戶中維護最低許可權,請只註冊您已準備好使用的資源提供者。
重要
如先前所述,請勿封鎖為處於註冊狀態的資源提供者建立資源。 當應用程式未封鎖處於註冊狀態的資源提供者時,其可以比等候所有區域完成還要快。
重新註冊 資源提供者,以使用您自先前註冊后新增的位置。
檢視資源提供者
若要查看特定資源提供者的資訊:
登入 Azure 入口網站。
選取 [Azure 入口網站] 功能表中的 [所有服務]。
在 [ 所有服務 ] 方塊中,輸入 資源總管,然後選取 [ 資源總管]。
選取向右箭號展開 [提供者]。
展開您想要檢視的資源提供者和資源類型。
所有區域都支援資源管理員,但您部署的資源可能無法在所有區域中受到支援。 此外,您的訂用帳戶可能會有一些限制,因此您無法使用某些支援資源的區域。 資源總管會顯示資源類型的有效位置。
API 版本會對應至資源提供者的 REST API 作業版本。 當資源提供者啟用新功能時,它會發行新版本的 REST API。 資源總管會顯示資源類型的有效 API 版本。
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...}
重要
如先前所述,請勿封鎖為處於註冊狀態的資源提供者建立資源。 當應用程式未封鎖處於註冊狀態的資源提供者時,其可以比等候所有區域完成還要快。
若要使用 Azure 自先前註冊后新增的位置,請再次註冊資源提供者。 若要重新註冊,請再次執行註冊命令。
若要查看特定資源提供者的資訊,請使用:
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
重要
如先前所述,請勿封鎖為處於註冊狀態的資源提供者建立資源。 當應用程式未封鎖處於註冊狀態的資源提供者時,其可以比等候所有區域完成還要快。
重新註冊資源提供者,以使用 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)
# 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
...
下一步
- 若要了解如何建立 Resource Manager 範本,請參閱了解 ARM 範本的結構和語法。
- 若要檢視資源提供者的範本架構,請參閱 使用 Bicep、ARM 範本和 Terraform AzAPI 提供者定義資源。
- 如需將資源提供者對應至 Azure 服務的清單,請參閱 Azure 服務的資源提供者。
- 若要檢視資源提供者的作業,請參閱 Azure REST API。