使用 ARM 模板通过服务主体身份验证为 Azure 数据工厂创建 API 连接

Create API Connection for Azure Data Factory with service principal authentication using ARM Template

我创建了一个使用 Azure 数据工厂连接器的逻辑应用程序。

我可以通过门户中的服务主体身份验证创建 API Connection

但我找不到任何关于如何使用 ARM 模板创建 API 连接的文档。

但我需要使用具有相同服务主体身份验证的 ARM 模板创建。

我在 visual studio 2019 年做了一些测试,因为 VS 将尽可能多地显示 ARM 模板的内容(有时显示的内容比 Azure 门户中的内容更多)。我安装了 "Azure Logic Apps Tools for Visual Studio 2019",然后在 VS2019 中创建了我的逻辑应用程序。添加动作"Create a pipeline run"后,在VS2019中点击"code view"。模板显示如下:

{
  "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
  "actions": {
    "Create_a_pipeline_run": {
      "type": "ApiConnection",
      "inputs": {
        "host": {
          "connection": {
            "name": "@parameters('$connections')['azuredatafactory_2']['connectionId']"
          }
        },
        "method": "post",
        "path": "/subscriptions/@{encodeURIComponent('**********')}/resourcegroups/@{encodeURIComponent('andywebbot')}/providers/Microsoft.DataFactory/factories/@{encodeURIComponent('andydatafactory2')}/pipelines/@{encodeURIComponent('pipeline1')}/CreateRun",
        "queries": {
          "x-ms-api-version": "2017-09-01-preview"
        }
      },
      "runAfter": {}
    }
  },
  "parameters": {
    "$connections": {
      "defaultValue": {},
      "type": "Object"
    }
  },
  "triggers": {
    "Recurrence": {
      "type": "Recurrence",
      "recurrence": {
        "frequency": "Month",
        "interval": 3
      }
    }
  },
  "contentVersion": "1.0.0.0",
  "outputs": {}
}

我们可以看到模板没有向我们显示连接的详细信息(例如 "tenantId"、"Client ID" 和 "Client Secret")。所以恐怕我们不能使用 ARM 模板来创建服务主体。

您可以使用 ARM 模板为 Azure 数据工厂创建 API 连接:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "connectionAPIName": {
      "type": "string"
    },
    "clientId": {
      "type": "string"
    },
    "clientSecret": {
      "type": "securestring"
    }
  },
  "resources": [
    {
      "type": "Microsoft.Web/connections",
      "apiVersion": "2018-07-01-preview",
      "name": "[parameters('connectionAPIName')]",
      "location": "[resourceGroup().location]",
      "properties": {
        "displayName": "[parameters('connectionAPIName')]",
        "parameterValues": {
          "token:clientId": "[parameters('clientId')]",
          "token:clientSecret": "[parameters('clientSecret')]",
          "token:TenantId": "[subscription().tenantId]",
          "token:grantType": "client_credentials"
        },
        "api": {
          "id": "[concat('subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/azuredatafactory')]"
        }
      }
    }
  ],
  "outputs": {}
}