7

I have a logic App (a standard logic app) that make a call to cosmos DB. I need to store the "Connection Runtime Url" under the configuration of the logic App.

When I create the connection from the logic app designer, the connection have this property. However, when I deploy the same connection using an ARM template, the connection don't have this property.

Anyone knows how can get this property or generate it? And if possible, how to call it later in an ARM template

Thanks

Thomas
  • 24,234
  • 6
  • 81
  • 125
ibda
  • 376
  • 3
  • 15

2 Answers2

7

Only API connection of kind: 'V2' can return a connectionRuntimeUrl.

You can create a cosmos db connector with the below script (bicep):

param location string = resourceGroup().location
param cosmosDbAccountName string = 'thomastestcosmos'
param connectorName string = '${cosmosDbAccountName}-connector'

// get a reference to the cosmos db account
resource cosmosDbAccount 'Microsoft.DocumentDB/databaseAccounts@2021-06-15' existing = {
  name: cosmosDbAccountName
}

// create the related connection api
resource cosmosDbConnector 'Microsoft.Web/connections@2018-07-01-preview' = {
  name: connectorName
  location: location
  kind: 'V2'
  properties: {
    displayName: connectorName
    parameterValues: {
      databaseAccount: cosmosDbAccount.name
      accessKey: cosmosDbAccount.listKeys().primaryMasterKey
    }
    api: {
      id: subscriptionResourceId('Microsoft.Web/locations/managedApis', location, 'documentdb') 
    }
  }
}

output connectionRuntimeUrl string = cosmosDbConnector.properties.connectionRuntimeUrl

The url will be an output of the generated ARM You can then set this url as an appsetting in the workflow app:

COSMOS_CONNECTION_RUNTIMEURL: <connectionRuntimeUrl>

Then in the connections.json file, you can reference this app setting:

{
  "managedApiConnections": {
    "documentdb": {
      ...
      "connectionRuntimeUrl": "@appsetting('COSMOS_CONNECTION_RUNTIMEURL')"
    }
  }
}

Using appsettings and parameters should make thing easier to deploy

Thomas
  • 24,234
  • 6
  • 81
  • 125
  • 2
    Yes, now this is working. The secret was that I needed to add 'Kind = V2' in my api connection template, according to: https://github.com/Azure/bicep/issues/3494 I wasn't able to see it before. Thanks Thomas – ibda Aug 19 '21 at 06:50
  • But @Thomas, it looks like when I make a call to appsetting in connections.json, my workflows didn't find the connection . It is not showing me any errors but Azure don't create a URL that I can use as a trigger to call this workflow. It looks like an internal error. I need to delete the action, click save (this will generate a URL), then copy and paste my original workflow.json and then click Run (I got a correct result at the end but I need some manual fixes as I explained). Any idea? – ibda Aug 20 '21 at 07:35
  • is it locally or after deploying ? – Thomas Aug 20 '21 at 09:18
  • The URL is not generated after deployment, and also locally if I created a new workflow manually and copy my ARM template manually and paste it under workflow -> code. and then saved. In both cases, I see no errors but no URL link is generated!!! – ibda Aug 20 '21 at 09:32
  • could you create another question or add more details ? Logic app standard deployment is tricky honestly – Thomas Aug 21 '21 at 01:28
  • I have created another question here: https://stackoverflow.com/questions/68863953/azure-generate-url-for-a-standard-logic-app-with-connection-to-cosmosdb – ibda Aug 23 '21 at 06:07
1

According to this discussion, a simple API connection (V1) may not have "connectionRuntimeUrl". So, to be able to see it I need to add

"kind": "V2",

in my connection Template, also as @Thomas wrote in his answer

Thomas
  • 24,234
  • 6
  • 81
  • 125
ibda
  • 376
  • 3
  • 15