]> Posts for June 2022 🌐:aligrant.com

Redeploying Azure Function App ARM/Bicep template deletes functions

Alastair Grant | Monday 27 June 2022

I encountered an irritating issue today: when redeploying my Bicep / ARM template for an Azure Function App (to deploy new config to an existing app), the functions stopped working.

Investigation

When looking at it closer, I discovered that the Functions themselves were reverting back to a stubbed state from the ARM template from prior to the first code drop, effectively deleting my published functions.  Clearly my ARM template is overwriting the config?  Well, no.  The stubs are conditional and don't get redeployed.  So what is going on?

Well I'm not entirely clear, but it's to do with how apps can be ran from packages.  The code being deployed was being deployed as a package, yet when you use the console to view the local file system, the files are all there to see (whether this is unpacked or mounted from an archive, I do not know, I'm sure it's documented somewhere).  When I redeployed my ARM template, I found that these files disappeared, and my function.json file reverted to the stub entry I put initially (which suggests some sort of mounting going on, as otherwise, where did that come from?).

The issue would only occur after my Function App was published; if instead I manually updated my stub function through the portal and then redeployed the ARM template, that stub would remain in the changed state and not revert.  So I then reviewed the difference between the configuration before and after the publishing of the code drop.  There are some configuration settings that get created as part of the deployment.

The simple approach to this is simply to republish your code every time you update your config, but in this scenario I have infrastructure changes in a separate pipeline process to the app changes, so even if I do trigger both pipelines on a change, I couldn't be sure which one would fire first without getting into all sorts of mess.

Fix

The missing configuration setting was WEBSITE_RUN_FROM_PACKAGE.  I added this to my Bicep deployment script, which when executed meant it retained the published code structure on the file system.

Breaking from the voyeuristic norms of the Internet, any comments can be made in private by contacting me.

Entries for: June 2022

Previous Next