After Azure Logic app deployment no event subscription is created on storage account

38 Views Asked by At

I have this Bicep file that creates a Logic app using "User managed identity". The Logic app is setup to trigger "When_a_resource_event_occurs" on a Storage account. The User managed identity has Owner access to the Storage account.

To my knowledge the deployment of the Bicep file, creating the Logic app, should automatically create the event subscription on the Storage account, but it doesn't. The deployment succeeds and I get no errors.

The Bicep looks like this. What am I missing?

param location string

param userAssignedIdentities_id_name string

param storageAccounts_name string
param connections_azureeventgrid_name string
param workflows_logic_name string

resource userAssignedIdentities_id_resource 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-07-31-preview' = {
  name: userAssignedIdentities_id_name
  location: location
}

resource connections_azureeventgrid_name_resource 'Microsoft.Web/connections@2018-07-01-preview' = {
  name: connections_azureeventgrid_name
  location: location
  kind: 'V1'
  properties: {
    displayName: connections_azureeventgrid_name
    api: {
      name: connections_azureeventgrid_name
      id: subscriptionResourceId('Microsoft.Web/locations/managedApis', location, 'azureeventgrid')
      type: 'Microsoft.Web/locations/managedApis'
    }
    parameterValueType: 'Alternative'
  }
}

resource workflows_logic__resource 'Microsoft.Logic/workflows@2017-07-01' = {
  name: workflows_logic_name
  location: location
  identity: {
    type: 'UserAssigned'
    userAssignedIdentities: {
      '/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/${userAssignedIdentities_id_name}':{}
    }
  }
  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: {
        '$connections': {
          defaultValue: {}
          type: 'Object'
        }
      }
      triggers: {
        When_a_resource_event_occurs: {
           inputs: {
            body: {
              properties: {
                destination: {
                  endpointType: 'webhook'
                  properties: {
                    endpointUrl: '@{listCallbackUrl()}'
                  }
                }
                filter: {
                  includedEventTypes: ['Microsoft.Storage.BlobCreated']
                  subjectBeginsWith: '/BlobServices/default/containers/toediprovider'
                }
                topic: '/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}/providers/Microsoft.Storage/storageAccounts/${storageAccounts_name}'
              }
            }
            host: {
              connection: {
                referenceName: 'azureeventgrid'
              }
            }
            path: '/subscriptions/${subscription().subscriptionId}/providers/Microsoft.Storage.StorageAccounts/resource/eventSubscriptions'
            queries: {
              subscriptionName: '${storageAccounts_name}-blobstorageevent'
              'x-ms-api-version': '2017-09-15-preview'

            }
          }
          type: 'ApiConnectionWebhook'
        }
      }
      actions: {
        //Removed for brevity
      }
      outputs: {}
    }
    parameters: {
      '$connections': {
        value: {
          azureeventgrid: {
            connectionId: connections_azureeventgrid_name_resource.id
            connectionName: 'azureeventgrid'
            connectionProperties: {
              authentication: {
                identity: userAssignedIdentities_id_resource.id
                type: 'ManagedServiceIdentity'
              }
            }
            id: subscriptionResourceId('Microsoft.Web/locations/managedApis', location, 'azureeventgrid')
          }
        }
      }
    }
  }
}

1

There are 1 best solutions below

0
wenbo On
  1. I have just tried your bicep code. it works at my side.
    my result:
    enter image description here

  2. your event subscription is including the Blob Created and Blob Deleted so just upload a file to your container, it will trigger. enter image description here

    enter image description here

  3. pay attention to you resource api version. link (not compulsory)

    • Microsoft.Web/connections@2016-06-01
    • Microsoft.Logic/workflows@2019-05-01