0

For the JSON below, I’m trying to get the list of locations for a specific resourceType.

This command:

az provider list --query "[?namespace=='Microsoft.Compute']" 

gives me the example output (too much to include all) at the end. How do I then query for specific resource types? I tried the following, but it doesn't work:

az provider list --query "[?contains(namespace, 'Microsoft.Compute')] | [?contains(resourceType, 'virtualMachines']"

Sample ouput from the first command:

[
  {
    "id": "/subscriptions/fed7f475-6055-4e3c-8529-c1345df70589/providers/Microsoft.Compute",
    "namespace": "Microsoft.Compute",
    "registrationState": "Registered",
    "resourceTypes": [
      {
        "aliases": null,
        "apiVersions": [
          "2017-03-30",
          "2016-08-30",
          "2016-04-30-preview",
          "2016-03-30",
          "2015-06-15",
          "2015-05-01-preview"
        ],
        "locations": [
          "East US",
          "East US 2",
          "West US",
          "Central US",
          "North Central US",
          "South Central US",
          "North Europe",
          "West Europe",
          "East Asia",
          "Southeast Asia",
          "Japan East",
          "Japan West",
          "Australia East",
          "Australia Southeast",
          "Brazil South",
          "South India",
          "Central India",
          "West India",
          "Canada Central",
          "Canada East",
          "West US 2",
          "West Central US",
          "UK South",
          "UK West",
          "Korea Central",
          "Korea South"
        ],
        "properties": null,
        "resourceType": "availabilitySets"
      },
  }
]
Oliver W.
  • 13,169
  • 3
  • 37
  • 50
Adoyt
  • 395
  • 2
  • 4
  • 17

1 Answers1

2

This should work:

az provider list --query "[?namespace=='Microsoft.Compute'].resourceTypes[].{resourceType:resourceType, locations:locations} | [?resourceType=='virtualMachines'] | [0].locations"

I'm not making any claims that it is the simplest way to do it - I'm still learning jmespath myself :)