Azure deployment can be hard.
To deploy and maintain azure resources, we are using bicep templates (a main template, invoking child modules to create individual resources). In addition we have environment-parameter-files, to encapsulate the differences between each environment.
Today, I had to add some Function App Alerts via the bicep-template. Basically the only part in this task, was to create a new module, that could create the Alerts for an array of Function Apps.
Feeling confident, I made the change, pushed it to the Azure Devops repository and invoked the Devops pipeline.
Sadly it failed with this very non-descriptive failure
ERROR: InvalidTemplate - Deployment template validation failed: 'The
template resource 'xxKeyVault' at line '1' and column '9939' is
not valid: The template function 'reference' is not expected at this
location. Please see https://aka.ms/arm-functions for usage details..
Please see https://aka.ms/arm-functions for usage details.'.
I had no idea about the reason – since i had changed nothing wrt. keyvaults and added no references.
az bicep lint showed no issues.
The ARM-template file that Devops was trying to deploy, was not available (we use MS agents)
Trying local deployment:
az deployment group what-if --name Test --resource-group rg-test-dev
--template-file modules\main.bicep --parameters params\dev.json
--subscription "Test - DEV" --mode Incremental
showed the same error – but gave no indications to the cause.
Doing a bicep build (az bicep build --file modules\main.bicep) produced a template-file, but it was clearly not identical to the one that Devops pipeline did
After hours of debugging, the error turned out to be simple:
module functionAppAlerts 'functionAppAlerts.bicep' = {
name: 'functionAppAlerts'
params: {
actionGroupId: actionGroups.outputs.actionGroupsId
timerTriggeredFunctionApps: functionAppNames_timerTriggered
location: location
tags: tags
}
}
I had not given the module a name.
Currently, I have no idea, how this oversight could lead to the error above.