您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

Azure 自定义资源提供程序概述Azure Custom Resource Providers Overview

Azure 自定义资源提供程序是 Azure 的可扩展平台。Azure Custom Resource Providers is an extensibility platform to Azure. 它允许你定义可用于丰富默认 Azure 体验的自定义 Api。It allows you to define custom APIs that can be used to enrich the default Azure experience. 本文档介绍:This documentation describes:

  • 如何生成和部署 Azure 自定义资源提供程序。How to build and deploy an Azure Custom Resource Provider.
  • 如何利用 Azure 自定义资源提供程序扩展现有工作流。How to utilize Azure Custom Resource Providers to extend existing workflows.
  • 在哪里可以找到要开始的指南和代码示例。Where to find guides and code samples to get started.

自定义提供程序概述

重要

自定义提供程序当前提供公共预览版。Custom Providers is currently in public preview. 此预览版在提供时没有附带服务级别协议,不建议将其用于生产工作负荷。This preview version is provided without a service level agreement, and it's not recommended for production workloads. 某些功能可能不受支持或者受限。Certain features might not be supported or might have constrained capabilities. 有关详细信息,请参阅 Microsoft Azure 预览版补充使用条款For more information, see Supplemental Terms of Use for Microsoft Azure Previews.

自定义资源提供程序可执行的操作What can custom resource providers do

下面是可以通过 Azure 自定义资源提供程序实现的一些示例:Here are some examples of what you can achieve with Azure Custom Resource Providers:

  • 扩展 Azure 资源管理器 REST API 以包括内部和外部服务。Extend Azure Resource Manager REST API to include internal and external services.
  • 启用自定义方案,使其位于现有 Azure 工作流之上。Enable custom scenarios on top of existing Azure workflows.
  • 自定义 Azure 资源管理器模板控件和效果。Customize Azure Resource Manager Templates control and effect.

什么是自定义资源提供程序What is a custom resource provider

Azure 自定义资源提供程序是通过在 Azure 和终结点之间创建约定来完成的。Azure Custom Resource Providers are made by creating a contract between Azure and an endpoint. 此协定通过新资源CustomProviders/resourceProviders定义新资源和操作的列表。This contract defines a list of new resources and actions through a new resource, Microsoft.CustomProviders/resourceProviders. 自定义资源提供程序随后会在 Azure 中公开这些新 Api。The custom resource provider will then expose these new APIs in Azure. Azure 自定义资源提供程序由三个部分组成:自定义资源提供程序、终结点和自定义资源。Azure Custom Resource Providers are composed of three parts: custom resource provider, endpoints, and custom resources.

如何生成自定义资源提供程序How to build custom resource providers

自定义资源提供程序是 Azure 与终结点之间的约定列表。Custom resource providers are a list of contracts between Azure and endpoints. 此合同介绍 Azure 应该如何与终结点进行交互。This contract describes how Azure should interact with an endpoint. 资源提供程序的行为类似于代理,并将向指定的终结点转发请求和响应。The resource provider acts like a proxy and will forward requests and responses to and from the specified endpoint. 资源提供程序可以指定两种类型的协定: resourceTypes操作A resource provider can specify two types of contracts: resourceTypes and actions. 通过终结点定义启用这些。These are enabled through endpoint definitions. 终结点定义由三个字段组成:名称routingType终结点An endpoint definition is comprised of three fields: name, routingType, and endpoint.

示例端点:Sample Endpoint:

{
  "name": "{endpointDefinitionName}",
  "routingType": "Proxy",
  "endpoint": "https://{endpointURL}/"
}
属性Property 必须Required 说明Description
namename 是的yes 终结点定义的名称。The name of the endpoint definition. Azure 会通过其 API 在“/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/Azure will expose this name through its API under '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/
resourceProviders/{resourceProviderName}/{endpointDefinitionName}”下公开此名称resourceProviders/{resourceProviderName}/{endpointDefinitionName}'
routingTyperoutingType 否**no 确定终结点的协定类型。Determines the contract type with the endpoint. 如果未指定,则会默认为 "Proxy"。If not specified, it will default to "Proxy".
endpointendpoint yes 终结点,可向其路由请求。The endpoint to route the requests to. 此项将处理响应以及请求的任何附带作用。This will handle the response as well as any side effects of the request.

构建自定义资源Building custom resources

ResourceTypes介绍添加到 Azure 的新自定义资源。ResourceTypes describe new custom resources that are added to Azure. 这些方法公开基本的 RESTful CRUD 方法。These expose basic RESTful CRUD methods. 了解有关创建自定义资源的详细信息See more about creating custom resources

包含resourceTypes的示例自定义资源提供程序:Sample Custom Resource Provider with resourceTypes:

{
  "properties": {
    "resourceTypes": [
      {
        "name": "myCustomResources",
        "routingType": "Proxy",
        "endpoint": "https://{endpointURL}/"
      }
    ]
  },
  "location": "eastus"
}

为上述示例添加到 Azure 的 Api:APIs added to Azure for the above sample:

HttpMethodHttpMethod 示例 URISample URI 说明Description
PUTPUT /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}//subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/
providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/
myCustomResources/{customResourceName}? api 版本 = 2018-09-01.txt-预览版myCustomResources/{customResourceName}?api-version=2018-09-01-preview
用于创建新资源的 Azure REST API 调用。The Azure REST API call to create a new resource.
DELETEDELETE /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}//subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/
providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/
myCustomResources/{customResourceName}? api 版本 = 2018-09-01.txt-预览版myCustomResources/{customResourceName}?api-version=2018-09-01-preview
Azure REST API 调用删除现有资源。The Azure REST API call to delete an existing resource.
GETGET /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}//subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/
providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/
myCustomResources/{customResourceName}? api 版本 = 2018-09-01.txt-预览版myCustomResources/{customResourceName}?api-version=2018-09-01-preview
Azure REST API 调用来检索现有资源。The Azure REST API call to retrieve an existing resource.
GETGET /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}//subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/
providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/
myCustomResources = 2018-09-01.txt-previewmyCustomResources?api-version=2018-09-01-preview
Azure REST API 调用来检索现有资源的列表。The Azure REST API call to retrieve the list of existing resources.

构建自定义操作Building custom actions

操作描述添加到 Azure 的新操作。Actions describe new actions that are added to Azure. 它们可以在资源提供程序的顶层公开,也可以嵌套在resourceType下。These can be exposed on top of the resource provider or nested under a resourceType. 了解有关创建自定义操作的详细信息See more about creating custom actions

包含操作的示例自定义资源提供程序:Sample Custom Resource Provider with actions:

{
  "properties": {
    "actions": [
      {
        "name": "myCustomAction",
        "routingType": "Proxy",
        "endpoint": "https://{endpointURL}/"
      }
    ]
  },
  "location": "eastus"
}

为上述示例添加到 Azure 的 Api:APIs added to Azure for the above sample:

HttpMethodHttpMethod 示例 URISample URI 说明Description
POSTPOST /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}//subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/
providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/
myCustomAction = 2018-09-01.txt-previewmyCustomAction?api-version=2018-09-01-preview
Azure REST API 调用来激活该操作。The Azure REST API call to activate the action.

寻求帮助Looking for help

如果有关于 Azure 自定义资源提供程序开发的问题,请尝试Stack OverflowIf you have questions for Azure Custom Resource Provider development, try asking on Stack Overflow. 该论坛上可能已有类似问题的解答,因此,在发贴之前请先查看以往的提问。A similar question may have already been asked and answered, so check first before posting. 添加标记 azure-custom-providers 可以快速得到回复!Add the tag azure-custom-providers to get a fast response!

后续步骤Next steps

本文介绍了自定义提供程序。In this article, you learned about custom providers. 若要创建自定义提供程序,请继续学习下一篇文章。Go to the next article to create a custom provider.