azureazure-functionsazure-resource-managerazure-bicep

Output newly created function app key using Bicep


I have a bicep template that creates a function app in a dedicated module. I would like out the function app key from the module. Anyone know how I can get the function key?

I can't find it in the list of properties:

enter image description here


Solution

  • If you would like to retrieve the default host key, you can use the listkeys function:

    param functionAppName string
    
    resource functionApp 'Microsoft.Web/sites@2022-09-01' existing = {
      name: functionAppName
    }
    
    resource functionAppHost 'Microsoft.Web/sites/host@2022-09-01' existing = {
      name: 'default'
      parent: functionApp
    }
    
    // Default host key
    output defaultHostKey string = functionAppHost.listKeys().functionKeys.default
    
    // Master key
    output masterKey string = functionAppHost.listKeys().masterKey
    
    // Addtionally grab the system keys
    output systemKeys object = functionAppHost.listKeys().systemKeys