United Kingdom: +44 (0)208 088 8978

Generating ARM templates with F#

We're hiring Software Developers

Click here to find out more

Deploying Infrastructure in Azure

Azure Resource Manager (ARM) templates are a great tool, providing the ability to declaratively specify entire application architectures and deploy them in an idempotent, repeatable fashion. However, authoring such templates is a difficult process, typically relying on custom tooling in e.g. Visual Studio. Official schema files exist from Microsoft that aim to provide compile-time checking of your templates, but are rarely kept up to date, meaning that authoring of an ARM templates often becomes an onerous task that is error-prone, difficult to understand and difficult to maintain.

Creating ARM templates the easy way

We've been looking for a way to harness the utility of ARM templates, without the authoring overhead, in a low-cost way. Therefore, we've begun the work on a project we call Farmer, which aims to provide a compile-time safe DSL to rapidly create ARM templates from the Microsoft .NET platform.

Here's an example Farmer "template"

/// Create a web application resource
let myWebApp = webApp {
    name "mysuperwebapp"
    sku WebApp.Sku.F1
}

/// The overall ARM template which has the webapp as a resource.
arm {
    location NorthEurope
    add_resource myWebApp
}

/// Deploy the template to Azure.
template
|> Writer.quickDeploy "my-resource-group-name"

This will generate and deploy an ARM template directly into Azure (including a fully configured and linked Application Insights instance), but instead of over 100+ lines over JSON, it's just a few lines of strongly-typed F#. Of course, you can simply generate the ARM template and manage the deployment process yourself!

Using something like F# also brings benefits such as a real programming language which enables use to implement proper logic to control how our template is generated, as well as introduce compile-time safety to ensure that the correct data is entered for specific attributes of a template. The DSL has been designed to prioritise simplicity first, so you don't need to know F# in order to use it!

Find out more

We currently have support for the most common Azure resources including:

  • App Service
  • Functions
  • Cosmos DB
  • SQL
  • Storage
  • Application Insights.

You can find out more about Farmer on our Github Repository. We're looking forward to hearing your ideas and trying this incubation project out.

Have (fun _ -> Ok())

Isaac