Simona Cotin
Jan 30 · 3 min read

When building a serverless API using Azure, we typically need to provision several resources:

  1. A storage account to save our code files
  2. An App Service plan to configure the consumption plan
  3. An App Service to execute our code
  4. An Application Insights instance to monitor our app

Ideally, because all these resources belong to the same logical application, we want to manage, monitor and deploy them as a group. If the provisioning of our App Service Plan has failed, we wouldn’t want to continue with the deployment of the other resources. The same holds for all the other resources.

With Azure Resource Manager we can use JSON templates to configure the creation of all these resources and dependencies between them. Azure Resource Manager is a tool for managing and provisioning resources into the cloud.


TLDR — you can copy the template that will generate all these resources from here .


To navigate your way in any ARM template, you need to know that the typical structure is:

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": []
}

The ready to deploy template file listed above is quite large so let’s break it down into the main sections:

  1. Parameters — this is where we can customize our deployment. In this template, we configure app name, storage account type and location to be dynamic. Every parameter has a name and a type, and optionally we can also configure defaultValue, allowedValues and metadata.

2. Variables — for reusable values throughout our template.

3. Resources — this section is where we declare all the resources that need to be created and their dependencies, aka this is where all the meat is!

Resources section in template

Note that this configuration will not only provision resources but also deploy the code from a given repository. To make sure you use your code as opposed to mine, you want to edit the parameters section:

"repoURL": {    "type": "string",    "defaultValue": "<your-repo-url-here>"},"branch": {    "type": "string",    "defaultValue": "<your-branch-here>"}

You could still use the template as is but that means it will deploy the master branch of my repository.

Deploy to Azure

Once we have a template defined that encapsulates our required resources we can add a “Deploy to Azure” button to our repository. In this example, we’ve created this template, and let’s add it to our GitHub repository:

In your repository’s Readme.md you need to add:

[![Deploy to Azure](https://azuredeploy.net/deploybutton.png)](https://portal.azure.com/#create/Microsoft.Template/uri/<your-encoded-azuredeploy.json-URL>)

Now anyone wanting to provision the same resources as you will only need to click a button:

Deploy to Azure

Now I call that awesome! 🎉


VS Code is a great tool to help you get started — make sure to install the Azure Resource Manager Tools extension and you will be able to generate new templates for all kinds of resources.

Checkout the quick start ARM templates, published on GitHub here. This is a collection of community contributed templates that you can use for other types of resources too, like databases, websites, etc.

Happy coding! 🐧

Microsoft Azure

Any language. Any platform. Our team is focused on making the world more amazing for developers and IT operations communities with the best that Microsoft Azure can provide. If you want to contribute in this journey with us, contact us at medium@microsoft.com

Thanks to sigje

Simona Cotin

Written by

Cloud Developer Advocate @Microsoft

Microsoft Azure

Any language. Any platform. Our team is focused on making the world more amazing for developers and IT operations communities with the best that Microsoft Azure can provide. If you want to contribute in this journey with us, contact us at medium@microsoft.com

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade