Deploying Functions with ARM templates and inline code

Last week I started a mini-series that focused on [Azure Functions and DevOps. The tooling is still being worked and in the interim we need a solution in order to do proper CI/CD with Azure Functions.

In this post we're looking into how to deploy Azure Functions using ARM Templates only. That's correct. This is a one stop solution but requires that you include your function code inline to the ARM JSON template. This is somewhat undocumented and I had to figure out how do it with help from the Azure PG (product group).

The good parts

Obviously this is a very simple solution. It only involves one step to deploy the code and it's all handled through the ARM template. You can include as many files as you want. If, for example, your Function relies on a couple of helper classes defined in other files, then these can be deployed side-by-side.

The bad parts

I think this is a truly "hack-y" solution. First of all, no developer in his/her right mind would be coding C#/node.js code inside JSON files. Secondly, the code needs to be properly escaped. This includes new lines (carriage return) and any quotes. In the end, it makes the code very hard to read and it's only applicable for very simple Functions.

Show me teh codez

Remember, you'll need a Service Principal to deploy your ARM template. Info on how to create and set it up accordingly can be found [here](GHOST_URL/service-principals-in-microsoft-azure/" target="_blank) and [here](GHOST_URL/automate-login-for-azure-powershell-scripts/" target="_blank).

The sample template with an inline, albeit very basic, Azure Function can be found below:

Or you can get use this link that has [highlighted lines](https://gist.github.com/cmatskas/bedfc1c2a6b72d62e46b40d0b773f111#file-azfunctionsinlinecode-json-L81-L107" target=_blank) with the Function definition including the inlined Function code!

Deploying the ARM template

Next, we need to fire up PowerShell or the Azure CLI and deploy that template to your preferred Resource Group on Azure. If you've never done an Azure Resource Manager (ARM) template before, there are very good step-by-step instructions in the [official Azure docs](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-template-deploy" target="_blank).

Next up - Azure Functions deployment with ARM Templates and MSBuild


  • Share this post on