How to Create a Logic App Connector in an ARM Template


pexels-photo-415043[1]I wanted to automate the performance test setup we discussed in the last article.  This includes a Logic App calling into a Cosmos DB stored procedure.

Logic App uses connectors when connecting to other services, either within or outside of Azure.  Now how do we create those in an ARM Template?  This problem is the same regardless if we want to connect to Cosmos DB, Blob Storage, an FTP site, SalesForce.com, Twitter, etc.  .

The problem

There is no schema definition of those as of this date (late October 2017).  If we using the “Automation Script” tab in the portal to reverse engineer the ARM template, it doesn’t quite work:  we can create the connection, but no provide the Cosmos DB credentials.  Using the Resource Explorer in the Portal gives a different yet still non-usable picture.

Solution

I reached out and found guidance from the very enthusiastic & helpful Jeff Hollan.

The guidance is quite simple yet very powerful since it will solve the problem for most connectors.

Basically:  use Visual Studio tools for Logic Apps, do the connection there and the tool will create the ARM template for us.

The tools are available for Visual Studio 2017 and Visual Studio 2015.

Specifically for Cosmos DB

I did navigate the web before finding an answer and I saw a lot of dead ends out there, so if you are looking specifically for Cosmos DB connector, here it is:


{
  "apiVersion": "2016-06-01",
  "type": "Microsoft.Web/connections",
  "name": "connector-resource-name-here",
  "location": "[resourceGroup().location]",
  "properties": {
    "displayName": "[concat('Connection to Cosmos DB account \"', parameters('Cosmos DB Account Name'), '\"')]",
    "api": {
      "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/documentdb')]"
    },
    "parameterValues": {
      "databaseAccount": "[parameters('Cosmos DB Account Name')]",
      "accessKey": "[listKeys(resourceId('Microsoft.DocumentDB/databaseAccounts', parameters('Cosmos DB Account Name')), '2015-04-08').primaryMasterKey]"
    }
  },
  "dependsOn": [
    "[resourceId('Microsoft.DocumentDB/databaseAccounts', parameters('Cosmos DB Account Name'))]"
  ]
}

Notice that we hook on a Cosmos DB account in order to list its keys. We assume the Cosmos DB account is part of the same deployment.

We could also simply hard code the primary or secondary key right there if the resource isn’t ours.

Summary

I hope this is useful for some out there as this had me banging my head on the wall for a few hours.

Advertisements

One thought on “How to Create a Logic App Connector in an ARM Template

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s