List Azure-ressourceplaceringer

Azure resources

azure.microsoft.com/en-us/global-infrastructure/geographies/

Hvis du vil oprette en ny resource group fra Azure CLI, kan du nemt gøre det sådan:

az group create --location westus -name MyResourceGroup

Men hvad nu hvis du gerne vil oprette en resource group i Europa eller Asien? Hvad skal du så skrive i stedet for westus?

For at få en komplet liste over tilgængelige placeringer kan du køre:

az account list-locations

Du får et langt output som dette:

[
  // ...
  {
    "displayName": "Brazil Southeast",
    "id": "/subscriptions/.../locations/brazilsoutheast",
    "metadata": {
      "geographyGroup": "South America",
      "latitude": "-22.90278",
      "longitude": "-43.2075",
      "pairedRegion": [
        {
          "id": "/subscriptions/.../locations/brazilsouth",
          "name": "brazilsouth",
          "subscriptionId": null
        }
      ],
      "physicalLocation": "Rio",
      "regionCategory": "Other",
      "regionType": "Physical"
    },
    "name": "brazilsoutheast",
    "regionalDisplayName": "(South America) Brazil Southeast",
    "subscriptionId": null
  }
]

Denne liste er svær at læse, og det, du har brug for, er name-egenskaben for hver placering. For kun at få navnene kan du bruge --query-parameteren:

az account list-locations --query "[*].name"

Nu er outputtet langt mere læsevenligt:

[
  "eastus",
  "eastus2",
  "southcentralus",
  "westus2",
  "australiaeast",
  // ...
  "norwaywest",
  "switzerlandwest",
  "ukwest",
  "uaecentral",
  "brazilsoutheast"
]

Men det ville stadig være rart at sortere listen alfabetisk:

az account list-locations --query "[*].name" --out tsv | sort

Output:

asia
asiapacific
australia
australiacentral
australiacentral2
australiaeast
australiasoutheast
brazil
brazilsouth
brazilsoutheast
canada
canadacentral
canadaeast
centralindia
centralus
centraluseuap
centralusstage
eastasia
eastasiastage
eastus
eastus2
eastus2euap
eastus2stage
eastusstage
europe
francecentral
francesouth
germanynorth
germanywestcentral
global
india
japan
japaneast
japanwest
jioindiawest
koreacentral
koreasouth
northcentralus
northcentralusstage
northeurope
norwayeast
norwaywest
southafricanorth
southafricawest
southcentralus
southcentralusstage
southeastasia
southeastasiastage
southindia
switzerlandnorth
switzerlandwest
uaecentral
uaenorth
uk
uksouth
ukwest
unitedstates
westcentralus
westeurope
westindia
westus
westus2
westus2stage
westus3
westusstage

Hvis du bruger PowerShell, kan du filtrere outputtet sådan:

az account list-locations --query "[*].name" `
    | ConvertFrom-Json `
    | sort `
    | where { $_ -like "*europe*" }

Output:

europe
northeurope
westeurope