Exploring Functions in Azure Bicep working with Logic Apps

Functions in Azure Bicep
There are many functions you can use in Azure Bicep to make your code more dynamic and one I use almost always for tagging is utcNow()
to get the days date. Kind of like in Powershell where you can use:
$currentDate = Get-Date -Format d
Bicep example:
param currentDate string = utcNow('yyyy-DD-mm')
And I will use this in a variable called deployment tags:
var deploymentTags = {
deploymentDate = currentDate
}
Along with some others of course.
The challenge we face
I was deploying an Azure Logic App with Azure Bicep that had an HTTP trigger and once one is provisioned something called an HTTP POST URL
gets populated that is a URL string.
This string is an endpoint URL that's generated after you save your workflow and is used for sending a request that triggers your workflow.

Where it says URL will be generated after save a link will be populated that looks something similar to this:
https://prod-148.westeurope.logic.azure.com:443/.....
I have not included the entire URL as it can be considered a secret of course and you should handle this with care.
But the challenge is that what if we deploy the logic app in Bicep and also deploy other resources where we need to supply this information? Let's say we are also creating an action group that contains a logic app receiver where we need to supply this information?
The information is provided first after you save/deploy the workflow so that means we are stuck?
The solution
This is where listCallBackUrl()
comes in. We can use this function to generate the information required so that we can feed this into the action group resource definition:
callbackUrl: listCallbackURL('${logicApp.id}/triggers/manual', '2019-05-01').value
Here is the entire logicAppReceivers
property:
logicAppReceivers: [
{
name: logicApp.name
callbackUrl: listCallbackURL('${logicApp.id}/triggers/manual', '2019-05-01').value
resourceId: logicApp.id
}
]
Important to ensure that you use the same API version in this entry as you used in your resource definition for the Logic App.
In this use case we are setting up a solution that triggers an action group to call on a logic app to do something, but obviously there are many more use cases available for this.
Which ones can you come up with?
The entire snippet:
resource logicApp 'Microsoft.Logic/workflows@2019-05-01' = {
name: logicAppName
location: location
tags: deploymentTags
properties: {
state: 'Enabled'
parameters: {
'$connections': {
'value': {
'office365': {
'connectionId': office365APIConnection.id
'connectionName': office365APIConnection.name
'id': '/subscriptions/${subscription().subscriptionId}/providers/Microsoft.Web/locations/${location}/managedApis/office365'
}
}
}
}
definition: logicAppConfiguration
}
}
resource actionGroup 'Microsoft.Insights/actionGroups@2022-06-01' = {
name: 'ag-resname'
location: 'global'
properties: {
enabled: true
groupShortName: 'ag-name'
logicAppReceivers: [
{
name: logicApp.name
callbackUrl: listCallbackURL('${logicApp.id}/triggers/manual', '2019-05-01').value
resourceId: logicApp.id
}
]
}
}
In this case the entire code-snippet lives in the same bicep file but you could modularize and separate these into different files and pass information about the Logic App resource ID using outputs
in your module.
References


About the author
