Search code examples
azureazure-functionsazure-logic-appsazure-resource-managerazure-bicep

How to add function app keys to logicapp app settings through Bicep


I am creating logic app and function app through Bicep configuration but need to update logicapp app settings with function app master key.

Below is the Bicep template:

resource funcapp 'Microsoft.Web/sites@2021-01-15' = {
  name: funcappname
  location: Location
  tags: tags
  kind: 'functionapp'
  properties: {
    enabled: true
    serverFarmId: spfuncapp.id
    ...
  }
}

resource logicappsite 'Microsoft.Web/sites@2021-01-15' = {
  name: logicapp
  location: Location
  tags: tags
  kind: 'functionapp,workflowapp'
  properties: {
    enabled: true
    serverFarmId: spD365LogicApp.id
    siteConfig: {
      appSettings: [
        {
          'name': 'azureFunctionOperation_functionAppKey'
          'value': '<function app master key here?'
        }
        ...
      ]
      ...
    }
    ...
  }
}

How can I add function app master key to logic app settings?


Solution

  • You can get the master key using the listKeys function:

    listKeys(resourceId('Microsoft.Web/sites/host', funcappname, 'default'), '2022-03-01').masterKey
    

    In you case, you could write something like that:

    appSettings = [
      {
        'name': 'azureFunctionOperation_functionAppKey'
        'value': listKeys(resourceId('Microsoft.Web/sites/host', funcapp.name, 'default'), '2022-03-01').masterKey
      }
    ]