Add A Function Key to Multiple Azure Functions in Bicep

Nick Anderson 0 Reputation points
2023-01-19T19:00:19.5933333+00:00

I am wondering how I can add a function key with a given name and value to multiple Azure Functions in Bicep.
User's image

From the Azure portal you are able to add additional function keys to your functions, and I would like to achieve the same thing by adding a specific key with a constant name and value to a list of different functions in my app via Bicep.

resource serverInstanceHeartbeat 'Microsoft.Web/sites/functions@2022-03-01' =  {
  parent: functionApp
  name: 'ServerInstances_Heartbeat'
  resource functionKey 'keys' =  {
    name: clientServerFunctionKeyName
    value: clientServerFunctionKeyValue
  }
}

I have tried to find a solution by adding the above to my bicep to add a single key, but I am met with the following exception:

'Could not find member 'value' on object of type 'TemplateResource'.

Any direction on this would be appreciated.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MikeUrnun 9,777 Reputation points Moderator
    2023-01-20T19:04:33.1266667+00:00

    Hello @Nick Anderson - Thanks for reaching out and posting on the MS Q&A!

    Function access keys are scoped to all the HTTP functions in your Function App. For creating them via a Bicep, could you try out the following sample and see if this does the trick?

    param FunctionAppName string  
    @secure()  
    param FunctionAppKey string  
      
    var keyName = 'MyAPIName-key'  
      
    resource FunctionAppName_default_keyName 'Microsoft.Web/sites/host/functionKeys@2022-03-01' = {  
      name: '${FunctionAppName}/default/${keyName}'  
      properties: {  
        name: keyName  
        value: FunctionAppKey  
      }  
    }
    

    For broader context, please review the answer I posted on the following thread: Creating a funtion app key using bicep

    If you encounter any problems, feel free to let me know in the comments section below with the relevant details, and I'd be happy to dig deeper and help you get unblocked.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.