Skip to content

Instantly share code, notes, and snippets.

@ninjarobot
Created November 14, 2021 15:02
Show Gist options
  • Save ninjarobot/0e28beb5c4f98510c58c62170c28ed76 to your computer and use it in GitHub Desktop.
Save ninjarobot/0e28beb5c4f98510c58c62170c28ed76 to your computer and use it in GitHub Desktop.
Example for deploying to multiple locations with Farmer
#r "nuget:Farmer"
open Farmer
open Farmer.Builders
// Sometimes resources aren't available in certain regions and another location needs to be chosen.
// The best way to do this is to create a nested resource group deployment to the _same_ resource
// group, and choose a different location for that nested deployment
arm {
location Location.WestEurope
add_resources [
storageAccount {
name "mywesteuropestorage1234"
}
resourceGroup { // Creates a nested deployment
name "[resourceGroup().name]" // but it will be to the same resource group
deployment_name "deploying-with-westeurope-resources"
location Location.NorthEurope // Specify the different location for these resources
add_resources [ // Add resources as normal.
storageAccount {
name "mynortheuropestorage9876"
}
]
}
]
} |> Writer.quickWrite "multiple-locations"
@ninjarobot
Copy link
Author

Resulting JSON

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "outputs": {},
  "parameters": {},
  "resources": [
    {
      "apiVersion": "2019-06-01",
      "dependsOn": [],
      "kind": "StorageV2",
      "location": "westeurope",
      "name": "mywesteuropestorage1234",
      "properties": {},
      "sku": {
        "name": "Standard_LRS"
      },
      "tags": {},
      "type": "Microsoft.Storage/storageAccounts"
    },
    {
      "apiVersion": "2020-10-01",
      "dependsOn": [],
      "name": "deploying-with-westeurope-resources",
      "properties": {
        "expressionEvaluationOptions": {
          "scope": "Inner"
        },
        "mode": "Incremental",
        "parameters": {},
        "template": {
          "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "outputs": {},
          "parameters": {},
          "resources": [
            {
              "apiVersion": "2019-06-01",
              "dependsOn": [],
              "kind": "StorageV2",
              "location": "northeurope",
              "name": "mynortheuropestorage9876",
              "properties": {},
              "sku": {
                "name": "Standard_LRS"
              },
              "tags": {},
              "type": "Microsoft.Storage/storageAccounts"
            }
          ]
        }
      },
      "resourceGroup": "[resourceGroup().name]",
      "tags": {},
      "type": "Microsoft.Resources/deployments"
    }
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment