So this will be a “quick post” that shows some great functionality within the Azure CLI with az account list-locations
. With this command you can expect some output like below, you actually get a lot of content back.
{
"displayName": "Brazil Southeast",
"id": "/subscriptions/949ef534-07f5-4138-8b79-aae16a71310c/locations/brazilsoutheast",
"metadata": {
"geographyGroup": "South America",
"latitude": "-22.90278",
"longitude": "-43.2075",
"pairedRegion": [
{
"id": "/subscriptions/949ef534-07f5-4138-8b79-aae16a71310c/locations/brazilsouth",
"name": "brazilsouth",
"subscriptionId": null
}
],
"physicalLocation": "Rio",
"regionCategory": "Other",
"regionType": "Physical"
},
"name": "brazilsoutheast",
"regionalDisplayName": "(South America) Brazil Southeast",
"subscriptionId": null
}
If you look at some of the examples, you will also see some “logical” locations, example below, there is a way of adding a query to remove these to display only “physical” locations.
{
"displayName": "United States",
"id": "/subscriptions/949ef534-07f5-4138-8b79-aae16a71310c/cations/unitedstates",
"metadata": {
"geographyGroup": null,
"latitude": null,
"longitude": null,
"pairedRegion": null,
"physicalLocation": null,
"regionCategory": "Other",
"regionType": "Logical"
},
"name": "unitedstates",
"regionalDisplayName": "United States",
"subscriptionId": null
}
I use a simple query to remove all locations without latitide and in my case simply return the Region Name 😄
az account list-locations --query "[?not_null(metadata.latitude)] .{RegionName:name}" --output json
{
"RegionName": "brazilsoutheast"
}
So, now to get the paired region, again if we look at the JSON output, there is ALWAYS only 1 result within the array for Paired Region; as per this only 1 paired region 😄. We will use this to our advantage
az account list-locations --query "[?not_null(metadata.latitude)] .{RegionName:name, PairedRegion:metadata.pairedRegion[0].name}" --output json
{
"PairedRegion": "brazilsouth",
"RegionName": "brazilsoutheast"
}