Last active
June 18, 2021 03:37
-
-
Save ninjarobot/668bd5e3d2368391d51a08f357bd4d05 to your computer and use it in GitHub Desktop.
Farmer application with multiple resource groups and traffic manager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r "nuget: Farmer, 1.6.0" | |
open Farmer | |
open Farmer.Builders | |
open Farmer.Builders.ContainerGroups | |
open Farmer.Builders.TrafficManager | |
open Farmer.TrafficManager | |
let msi = userAssignedIdentity { | |
name "my-app" | |
} | |
let containerApp = | |
containerGroup { | |
name "my-containers" | |
add_identity msi | |
public_dns "my-container-app-1234" [ TCP, 80us ] | |
add_instances [ | |
containerInstance { | |
name "web" | |
image "nginx" | |
add_public_ports [ 80us ] | |
probes [ | |
liveliness { | |
http "http://localhost:80/" | |
initial_delay_seconds 15 | |
} | |
] | |
} | |
] | |
} | |
arm { | |
add_resources [ | |
resourceGroup { | |
name "global-rg" | |
location Location.EastUS | |
add_resources [ | |
trafficManager { | |
name "tm-app-global" | |
routing_method RoutingMethod.Performance | |
add_endpoints [ | |
endpoint { | |
name "eastus-app" | |
weight 1 | |
priority 1 | |
target_external "my-container-app-1234.eastus.azurecontainer.io" Location.EastUS | |
} | |
endpoint { | |
name "westus-app" | |
weight 1 | |
priority 2 | |
target_external "my-container-app-1234.westus.azurecontainer.io" Location.WestUS | |
} | |
endpoint { | |
name "westeu-app" | |
weight 1 | |
priority 3 | |
target_external "my-container-app-1234.westeurope.azurecontainer.io" Location.WestEurope | |
} | |
endpoint { | |
name "india-app" | |
weight 1 | |
priority 4 | |
target_external "my-container-app-1234.centralindia.azurecontainer.io" Location.CentralIndia | |
} | |
endpoint { | |
name "asia-app" | |
weight 1 | |
priority 5 | |
target_external "my-container-app-1234.eastasia.azurecontainer.io" Location.EastAsia | |
} | |
] | |
} | |
] | |
} | |
resourceGroup { | |
name "app-westus-rg" | |
location Location.WestUS | |
add_resources [ | |
msi | |
containerApp | |
] | |
} | |
resourceGroup { | |
name "app-eastus-rg" | |
location Location.EastUS | |
add_resources [ | |
msi | |
containerApp | |
] | |
} | |
resourceGroup { | |
name "app-westeu-rg" | |
location Location.WestEurope | |
add_resources [ | |
msi | |
containerApp | |
] | |
} | |
resourceGroup { | |
name "app-asia-rg" | |
location Location.EastAsia | |
add_resources [ | |
msi | |
containerApp | |
] | |
} | |
resourceGroup { | |
name "app-india-rg" | |
location Location.CentralIndia | |
add_resources [ | |
msi | |
containerApp | |
] | |
} | |
] | |
} |> Writer.quickWrite "global-app" |
Create the resource groups in different regions, then run the global deployment, which deploys Traffic Manager with optimized routing and failover to traffic in different regions:
az group create -g global-rg --location EastUS
az group create -g app-eastus-rg --location EastUS
az group create -g app-westus-rg --location WestUS
az group create -g app-westeu-rg --location WestEurope
az group create -g app-india-rg --location CentralIndia
az group create -g app-asia-rg --location EastAsia
az deployment sub create --location EastUS --template-file global-app.json
Cleanup
az group delete -g global-rg -y --no-wait
az group delete -g app-eastus-rg -y --no-wait
az group delete -g app-westus-rg -y --no-wait
az group delete -g app-westeu-rg -y --no-wait
az group delete -g app-india-rg -y --no-wait
az group delete -g app-asia-rg -y --no-wait
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The ARM template JSON: