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