Azure ARM Templates

There are times when you need to replicate a deployment environment. A very common example is that a team usually has multiple environments for development, testing, staging, and production. Also at times, you need a secondary production environment for resiliency. Manually creating environments can be a lengthy and error-prone process. A simple configuration miss can be hard to detect and cause major issues.

ARM or Azure Resource Manager templates comes to help here. ARM provides us to implement Infrastructure as Code.

ARM templates are JavaScript Object Notation (JSON) files that define the infrastructure and configuration for your deployment. The template uses a declarative syntax. The declarative syntax is a way of building the structure and elements that outline what resources will look like without describing its control flow. Declarative syntax is different than imperative syntax, which uses commands for the computer to perform. Imperative scripting focuses on specifying each step in deploying the resources.

https://docs.microsoft.com/en-gb/learn/modules/create-azure-resource-manager-template-vs-code/2-explore-template-structure?tabs=azure-cli

ARM templates are idempotent, which means you can deploy the same template many times and get the same resource types in the same state.

Element Description

  • schema: A required section that defines the location of the JSON schema file that describes the structure of JSON data.
  • contentVersion: A required section that defines the version of your template (such as 1.0.0.0).
  • apiProfile: An optional section that defines a collection of API versions for resource types.
  • parameters: An optional section where you define values that are provided during deployment.
  • variables: An optional section where you define values that are used to simplify template language expressions.
  • resources: A required section that defines the actual items you want to deploy or update in a resource group or a subscription.
  • output: An optional section where you specify the values that will be returned at the end of the deployment.

Example

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.1",
  "apiProfile": "",
  "parameters": {},
  "variables": {},
  "functions": [],
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "apiVersion": "2019-06-01",
      "name": "learntemplatestorage123",
      "location": "westus",
      "sku": {
        "name": "Standard_LRS"
      },
      "kind": "StorageV2",
      "properties": {
        "supportsHttpsTrafficOnly": true
      }
    }
  ],
  "outputs": {}
}