We have a logic app with managed identity to communicate with a service bus.
After we have deployed the solution by ARM or Bicep, we manually give logic app access to service bus by adding the logic app to sender/receiver role.
Then we test the logic app to see if it has access to service bus.
Often, not always, we get this error: "40100: Unauthorized : Unauthorized access for 'Send' operation on endpoint 'sb://[sb-name].servicebus.windows.net/[queue-name]'
To fix this we make a new api connection to the service bus within the logic app. Then it works. It seems to me that the api connection deployed by ARM/Bicep somehow gets broken in the deployment process.
Service bus
resource namespaces_servicebus 'Microsoft.ServiceBus/namespaces@2022-10-01-preview' = {
name: servicebus
location: location
sku: {
name: 'Basic'
tier: 'Basic'
}
properties: {
premiumMessagingPartitions: 0
minimumTlsVersion: '1.2'
publicNetworkAccess: 'Enabled'
disableLocalAuth: false
zoneRedundant: false
}
}
Api connection
resource connections_servicebus 'Microsoft.Web/connections@2018-07-01-preview' = {
name: connections_servicebus
location: location
kind: 'V1'
dependsOn: [
namespaces_servicebus
]
properties: {
displayName: connections_servicebus_name
api: {
id: subscriptionResourceId('Microsoft.Web/locations/managedApis', location, 'servicebus')
}
parameterValueSet: {
name: 'managedIdentityAuth'
values: {
namespaceEndpoint: {
value: 'sb://${namespaces_servicebus}.servicebus.windows.net/'
}
}
}
}
}
Logic app
resource workflows_logicapp 'Microsoft.Logic/workflows@2019-05-01' = {
name: workflows_name
location: location
identity: {
type: 'SystemAssigned'
}
properties: {
state: 'Enabled'
definition: {
'$schema': 'https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#'
contentVersion: '1.0.0.0'
parameters: {
[removed for brevity]
}
triggers: {
[removed for brevity]
}
actions: {
[removed for brevity]
}
outputs: {
[removed for brevity]
}
}
parameters: {
'$connections': {
value: {
servicebus: {
id: subscriptionResourceId('Microsoft.Web/locations/managedApis', location, 'servicebus')
connectionId: connections_servicebus.id
connectionName: 'servicebus'
connectionProperties: {
authentication: {
type: 'ManagedServiceIdentity'
}
}
}
}
}
}
}
}