Multi-Region ARM Deployments

Azure solutions that span multiple regions are more and more requested.  There are several options to deploy Azure resources across regions and ARM templates are one of them.  It’s very easy, let me explain!

In this example, we’ll deploy an App Service Plan in two regions.  One will act as the primary region, the other region will be a hot stand-by (secondary).

  • Configure an input parameter of the type array.  Here, it’s called “regions”, with West and North Europe as default values.
    "parameters": {
        "regions": {
            "type": "array",
            "defaultValue": [
                {
                    "location": "West Europe",
                    "prefix": "we-primary"
                },
                {
                    "location": "North Europe",
                    "prefix": "ne-secondary"
                }
            ],
            "metadata": {
                "description": "Locations"
            }
        }
    },
  • Decorate the App Service Plan with the copy function, which allows to deploy multiple instances of the same resource.
            "copy" : {
                "name": "regionCopy",
                "count": "[length(parameters('regions'))]"
            },
  • Leverage the copyIndex() to dynamically identify the location and prefix
    "resources": [
        {
            "apiVersion": "2015-08-01",
            "copy" : {
                "name": "regionCopy",
                "count": "[length(parameters('regions'))]"
            },
            "name": "[concat('tvh-', parameters('regions')[copyIndex()].prefix, '-appSvcPlan')]",
            "type": "Microsoft.Web/serverfarms",
            "location": "[parameters('regions')[copyIndex()].location]",
            "sku": {
                "name": "F1"
            },
            "properties": {
            }
        }
    ]
  • As a result, you have an App Service Plan deployed in each region!

I hope this trick will help you to achieve multi-regional Infrastructure as Code!

Cheers,
Toon

About the Author:

Toon is Lead Architect at Codit Belgium and a Microsoft Azure MVP. His duty is to design and deliver reliable, secure and scalable integration / backend solutions, both on-premises and in the Azure cloud. His focus is on integration, API Management, IoT and Azure PaaS solutions. As a solution architect, he’s not scared to take up big challenges and to dive into a development mode.

He’s a quite active member of the Microsoft Azure community and was speaker on several community and company events. Being a Microsoft Certified Trainer, he loves to share his experiences in workshops, presentations and blogs. As an Azure Advisor, he’s actively collaborating with various Azure product teams.

Reference:

Vanhoutte, T. (2019). Multi-region ARM deployments. Available at: https://toonvanhoutte.wordpress.com/2019/12/10/multi-region-arm-deployments/ [Accessed: 17th May 2020].

Check out more great Azure content here

Share this on...

Rate this Post:

Share: