1
votes

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.

2

2 Answers

1
votes

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

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.