Search code examples
azureazure-cloud-servicesazure-bicep

Create an Api connection to log analytics workspace via bicep


i am trying to create api connection to use by logic app through bicep. Below is code.

resource logicApp 'Microsoft.Web/sites@2022-09-01' existing = {
  name: logicAppName
}

resource logworkspace 'Microsoft.OperationalInsights/workspaces@2022-10-01' existing = {
  name: logAnalyticsWorkspace
  scope: resourceGroup(lawresourcegroup)
}

resource loganalyticsconnection 'Microsoft.Web/connections@2016-06-01' = {
  name: 'lawconnection'
  location: location
  kind: 'V2'
  properties: {
    displayName: 'loganalyticsconn'
    api: {
      id: '/subscriptions/${subscription().subscriptionId}/providers/Microsoft.Web/locations/${location}/managedApis/azuremonitorlogs'
    }
    parameterValues: {
      workspace: logworkspace.id
      authentication: {
        type: 'ManagedServiceIdentity'
        identity: logicApp.identity.principalId
      }
    }
  }
}

however it is failing with the following error Parameter 'workspace' is not allowed on the connection since it was not defined as a connection parameter when the API was registered

thanks in advance


Solution

  • You can refer to this documentation: Authenticate access and connections to Azure resources with managed identities in Azure Logic Apps

    Also I've created a logic app and connector from the portal with the network tab opened, this matches the request sent to ARM Api to create the connector:

    resource logicApp 'Microsoft.Web/sites@2022-09-01' existing = {
      name: logicAppName
    }
    
    resource logworkspace 'Microsoft.OperationalInsights/workspaces@2022-10-01' existing = {
      name: logAnalyticsWorkspace
      scope: resourceGroup(lawresourcegroup)
    }
    
    resource loganalyticsconnection 'Microsoft.Web/connections@2018-07-01-preview' = {
      name: 'lawconnection'
      location: location
      kind: 'V2'
      properties: {
        api: {
          id: subscriptionResourceId('Microsoft.Web/locations/managedApis', location, 'azuremonitorlogs')
        }
        authenticatedUser: {}
        displayName: 'loganalyticsconn'
        parameterValueSet: {
          name: 'managedIdentityAuth'
          values: {}
        }
      }
    }