共用方式為


Azure 自訂資源提供者資源上線概觀

Azure 自訂資源提供者資源上線是 Azure 資源類型的擴充性模型。 可用來大規模在現有 Azure 資源之間套用作業或管理。 如需詳細資訊,請參閱 Azure 自訂資源提供者如何擴充 Azure。 本文章說明:

  • 資源上線有什麼功能。
  • 資源上線的基本概念及使用方式。
  • 何處可以找到指南和程式碼範例以開始使用。

重要

自訂資源提供者目前處於公開預覽狀態。 此預覽版本沒有服務等級協定,不建議用於處理生產工作負載。 可能不支援特定功能,或部分功能可能受限。 如需詳細資訊,請參閱 Microsoft Azure 預覽版增補使用條款

資源上線有什麼用途?

類似於 Azure 自訂資源提供者自訂資源,資源上線功能可定義合約,以便代理對端點的「上線」要求。 與自訂資源不同的是,資源上線不會建立新的資源類型。 而是會允許現有資源類型的擴充功能。 資源上線可與 Azure 原則搭配使用,因此能大規模管理和設定資源。 資源上線工作流程的一些範例:

  • 安裝和管理虛擬機器擴充功能。
  • 上傳並設定 Azure 儲存體帳戶的預設值。
  • 大規模啟用基準診斷設定。

資源上線基本概念

您可以使用 Microsoft.CustomProviders/resourceProviders 和 Microsoft.CustomProviders/associations 資源類型,透過 Azure 自訂資源提供者設定資源上線。 若要啟用自訂資源提供者的資源上線功能,請在設定過程中建立名為 "association" 的 resourceType,而 routingType 包含 "Extension"。 Microsoft.CustomProviders/associations 和 Microsoft.CustomProviders/resourceProviders 不需要屬於相同的資源群組。

以下是 Azure 自訂資源提供者的範例:

{
  "properties": {
    "resourceTypes": [
      {
        "name": "associations",
        "routingType": "Proxy,Cache,Extension",
        "endpoint": "https://microsoft.com/"
      }
    ]
  },
  "location": "eastus"
}
屬性 是必要的嗎? 描述
NAME Yes 端點定義的名稱。 若使用資源上線,名稱必須是 "associations"。
routingType Yes 判斷端點的合約類型。 針對資源上線,有效的 routingTypes 為 "Proxy,Cache,Extension" 和 "Webhook,Cache,Extension"。
endpoint Yes 要作為要求路由傳送目的地的端點。 這會處理回應及要求的任何副作用。

建立具有關聯資源類型的自訂資源提供者之後,便可使用 Microsoft.CustomProviders/associations 來設定目標。 Microsoft.CustomProviders/associations 是擴充功能資源,可延伸任何其他 Azure 資源。 建立 Microsoft.CustomProviders/associations 的執行個體時,會採用 targetResourceId 屬性,這應該是有效的 Microsoft.CustomProviders/resourceProviders 或 Microsoft.Solutions/applications 資源識別碼。 在這些情況下,系統會將要求轉送至您所建立 Microsoft.CustomProviders/resourceProviders 執行個體上的關聯資源類型。

注意

如果以 targetResourceId 形式提供 Microsoft.Solutions/applications 資源識別碼,就必須在名稱為 "public" 的受控資源群組中部署 Microsoft.CustomProviders/resourceProviders。

Azure 自訂資源提供者關聯範例:

{
  "properties": {
    "targetResourceId": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}",
    ...
  }
}
屬性 是必要的嗎? 描述
targetResourceId Yes Microsoft.CustomProviders/resourceProviders 或 Microsoft.Solutions/applications 的資源識別碼。

如何使用資源上線

資源上線的運作方式是使用 Microsoft.CustomProviders/associations 擴充功能資源來擴充其他資源。 下列範例是對虛擬機器提出要求,但任何資源都可以擴充。

首先,需建立具有關聯資源類型的自訂資源提供者資源。 這會宣告在建立以自訂資源提供者為目標的對應 Microsoft.CustomProviders/associations 資源時,將使用的回撥 URL。

Microsoft.CustomProviders/resourceProviders 建立要求的範例:

PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}?api-version=2018-09-01-preview
Authorization: Bearer eyJ0e...
Content-Type: application/json

{
  "properties": {
    "resourceTypes": [
      {
        "name": "associations",
        "routingType": "Proxy,Cache,Extension",
        "endpoint": "https://{myCustomEndpoint}/"
      }
    ]
  },
  "location": "{location}"
}

建立自訂資源提供者之後,您可以將其他資源設為目標,並將自訂資源提供者的副作用套用至這些資源。

Microsoft.CustomProviders/associations 建立要求的範例:

PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{virtualMachineName}/providers/Microsoft.CustomProviders/associations/{associationName}?api-version=2018-09-01-preview
Authorization: Bearer eyJ0e...
Content-Type: application/json

{
  "properties": {
    "targetResourceId": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}",
    "myProperty1": "myPropertyValue1",
    "myProperty2": {
        "myProperty3" : "myPropertyValue3"
    }
  }
}

然後系統會將此要求轉送到您建立的自訂資源提供者中指定的端點,targetResourceId 會透過下列形式參考該端點:

PUT https://{endpointURL}/?api-version=2018-09-01-preview
Content-Type: application/json
X-MS-CustomProviders-RequestPath: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/associations/{associationName}
X-MS-CustomProviders-ExtensionPath: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{virtualMachineName}/providers/Microsoft.CustomProviders/associations/{associationName}
X-MS-CustomProviders-ExtendedResource: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{virtualMachineName}

{
  "properties": {
    "myProperty1": "myPropertyValue1",
    "myProperty2": {
        "myProperty3" : "myPropertyValue3"
    }
  }
}

端點應以 application/json Content-Type 和有效的 JSON 回應主體回應。 JSON 的 properties 物件底下傳回的欄位,將會加入關聯傳回回應中。

取得說明

如果您對 Azure 自訂資源提供者開發有任何疑問,請嘗試在 Stack Overflow (英文) 上提問。 類似的問題可能已有人回答,因此請先查看再張貼問題。 新增標記 azure-custom-providers 以取得快速回應!

下一步

在此文章中,您已瞭解自訂資源提供者。 若要深入了解,請參閱下列文章: