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

爱⌒轻易说出口 提交于 2021-01-29 13:18:26

问题


I've created a logic app that uses azure data factory connectors.

I can create the API Connection with service principal authentication from the portal:

But I can't find any documentation on how to create an API connection using ARM template.

But I need to create using ARM template with the same service principal authentication.


回答1:


You can create an API connection for Azure Data factory using ARM template like that:

{
  "$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": {}
}



回答2:


I did some test in visual studio 2019 because VS will show as much content of ARM template as possible(sometimes show the content more than in Azure portal). I installed "Azure Logic Apps Tools for Visual Studio 2019" and then create my logic app in VS2019. After adding an action "Create a pipeline run", click "code view" in VS2019. The template shows as below:

{
  "$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": {}
}

We can see the template doesn't show us the details of the connection(such as "tenantId", "Client ID" and "Client Secret"). So I'm afraid we can not use ARM template to create the service principal.



来源:https://stackoverflow.com/questions/57889261/create-api-connection-for-azure-data-factory-with-service-principal-authenticati

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!