Reputation: 8741
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:
Upvotes: 5
Views: 7282
Reputation: 345
The current accepted answer creates a warning in the bicep file, which can complicate CI/CD pipelines.
Also, I agree with people that you should not attempt to return keys through output.
A valid use, though, is to store that default key in a KeyVault for later use.
The way I found to do this is with the following code in a bicep file:
listKeys('${functionAppResource.id}/host/default', functionAppResource.apiVersion).functionKeys.default
Fo those interested I found the above snippet from an Azure kickstart template in Github.
Upvotes: 0
Reputation: 39
We should never return keys using output as it gets logged with the deployment. We can use lisKeys() method to get the function keys.
Upvotes: 0
Reputation: 29736
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
Upvotes: 14