1

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:

enter image description here

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.

Thomas
  • 24,234
  • 6
  • 81
  • 125
Manish Jain
  • 217
  • 1
  • 4
  • 16

2 Answers2

2

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": {}
}
Thomas
  • 24,234
  • 6
  • 81
  • 125
  • Thanks @Thomas, it works. Can you please tell me where these keys(clientId, clientSecret) are defined. Is there any document. Because I need same for cosmosDB connection where I need to put 'accountId', 'accessKey' etc. – Manish Jain Sep 16 '19 at 12:10
  • 1
    I never found any documentation around that. What I did is open `developer tools` on azure portal before creating the connector manually then I was able to see the ARM request... I know it is a bit of a pain but this is the easiest method I've found. – Thomas Sep 16 '19 at 12:14
  • @Thomas: I've deployed the connector as described but the connector reports as 'Unauthenticated'. Have you come across anything similar? – haymansfield Sep 03 '20 at 11:29
  • did you run `connect-azaccount` before ? – Thomas Sep 04 '20 at 21:48
0

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.

Hury Shen
  • 14,948
  • 1
  • 9
  • 18