Create Azure Connection API with Connection Runtime Url
Asked Answered
F

2

8

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

Federal answered 18/8, 2021 at 10:17 Comment(0)
T
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

Titos answered 19/8, 2021 at 4:2 Comment(8)
Yes, now this is working. The secret was that I needed to add 'Kind = V2' in my api connection template, according to: github.com/Azure/bicep/issues/3494 I wasn't able to see it before. Thanks ThomasFederal
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?Federal
is it locally or after deploying ?Titos
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!!!Federal
could you create another question or add more details ? Logic app standard deployment is tricky honestlyTitos
I have created another question here: #68864453Federal
Does not look like this is valid anymore, since the available APIs atm are: 2015-08-01-preview 2016-06-01 learn.microsoft.com/en-us/azure/templates/microsoft.web/… I was able to get it to work with the '2015-08-01-preview' one. output connectionRuntimeUrl string = apiConnection.properties.metadata.connectionRuntimeUrlFelucca
Actually, that API does not work foe SQL connections, so we had to go with the reference method instead: output connectionRuntimeUrl string = reference(apiConnection.id, apiConnection.apiVersion, 'full').properties.connectionRuntimeUrlFelucca
F
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

Federal answered 19/8, 2021 at 6:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.