Paul
Paul

Reputation: 1620

How to set the connection string for a Service Bus Logic App action in an ARM template?

I'm attempting to deploy an Azure Logic App that includes an action to Send a message on a Service Bus using an ARM template.

In addition to deploying the Logic App, the ARM template deploys a Service Bus Namespace, a Queue and two AuthorizationRule (one for sending and one for listening).

I want to dynamically set the connection information for the Send Service Bus Message action to use the Connection string generated for the AuthorizationRule that supports sending.

When I create this in the portal editor (specifying the connection string for sending), I noticed the following is generated in code view...

"Send_message.": {
    "conditions": [
        {
            "dependsOn": "<previous action>"
        }
    ],
    "inputs": {
        "body": {
            "ContentData": "@{encodeBase64(triggerBody())}"
        },
        "host": {
            "api": {
                "runtimeUrl": "https://logic-apis-westus.azure-apim.net/apim/servicebus"
            },
            "connection": {
                "name": "@parameters('$connections')['servicebus']['connectionId']"
            }
        },
        "method": "post",
        "path": "/@{encodeURIComponent(string('<queuename>'))}/messages"
    },
    "type": "apiconnection"
}

},

I assume that the connection information is somehow buried in @parameters('$connections')['servicebus']['connectionId']"

I then used resources.azure.com to navigate to the logic app to see if I could get more details as to how @parameters('$connections')['servicebus']['connectionId']" is defined.

I found this:

"parameters": {
  "$connections": {
    "value": {
      "servicebus": {
        "connectionId": "/subscriptions/<subguid>/resourceGroups/<rgname>/providers/Microsoft.Web/connections/servicebus",
        "connectionName": "servicebus",
        "id": "/subscriptions/<subguid>/providers/Microsoft.Web/locations/westus/managedApis/servicebus"
      }
    }
  }
}

But I still don't see where the connection string is set.

Where can I set the connection string for the service bus action in an ARM template using something like the following?

[listkeys(variables('sendAuthRuleResourceId'), variables('sbVersion')).primaryConnectionString]

EDIT: Also, I've referred to was seems to be a promising Azure quick start on github (based on the title), but I can't make any sense of it. It appears to use an older schema 2014-12-01-preview, and the "queueconnector" references an Api Gateway. If there is a newer example out there for this scenario, I'd love to see it.

Upvotes: 1

Views: 9309

Answers (2)

Kathiravan
Kathiravan

Reputation: 81

I've recently worked on an ARM Template for the deployment of logic apps and service bus connection. Here is the sample template for configuring service bus connection string within the type "Microsoft.Web/connections". Hope it helps.

 {
    "type": "Microsoft.Web/connections",
    "apiVersion": "2016-06-01",
    "name": "[parameters('connections_servicebus_name')]",
    "location": "centralus",
    "dependsOn": [
      "[resourceId('Microsoft.ServiceBus/namespaces/AuthorizationRules', parameters('ServiceBusNamespace'), 'RootManageSharedAccessKey')]"
    ],
    "properties": {
      "displayName": "ServiceBusConnection",
      "customParameterValues": {},
      "api": {
        "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/centralus/managedApis/servicebus')]"
      },
      "parameterValues": {
        "connectionString": "[listKeys(resourceId('Microsoft.ServiceBus/namespaces/authorizationRules', parameters('ServiceBusNamespace'), 'RootManageSharedAccessKey'), '2017-04-01').primaryConnectionString]"
      }
    }
  }

Upvotes: 6

TusharJ
TusharJ

Reputation: 1263

As you know connections is a resource so it needs to be created first did you refer this https://blogs.msdn.microsoft.com/logicapps/2016/02/23/deploying-in-the-logic-apps-preview-refresh/. Quick start link you are referring is for older schema.

Upvotes: 3

Related Questions