Search code examples
azure-cloud-shell

azure: az resource list missing tags


It tells me I have null tags if I list my resources with az resource list --tag Departement=Finance

az resource list --tag Departement=Finance
[
  {
    "id": "/subscriptions/28b7bf82-0a7d-4ca7-9827-811c620d6d52/resourceGroups/msftlearn-core-infrastructure-rg/providers/Microsoft.Network/virtualNetworks/msftlearn-vnet1",
    "identity": null,
    "kind": null,
    "location": "switzerlandnorth",
    "managedBy": null,
    "name": "msftlearn-vnet1",
    "plan": null,
    "properties": null,
    "resourceGroup": "msftlearn-core-infrastructure-rg",
    "sku": null,
    "tags": null,
    "type": "Microsoft.Network/virtualNetworks"
  }
]

But with az resource list --resource-group msftlearn-core-infrastructure-rg it shows me all the tags.

az resource list --resource-group msftlearn-core-infrastructure-rg
[
  {
    "id": "/subscriptions/28b7bf82-0a7d-4ca7-9827-811c620d6d52/resourceGroups/msftlearn-core-infrastructure-rg/providers/Microsoft.Network/virtualNetworks/msftlearn-vnet1",
    "identity": null,
    "kind": null,
    "location": "switzerlandnorth",
    "managedBy": null,
    "name": "msftlearn-vnet1",
    "plan": null,
    "properties": null,
    "resourceGroup": "msftlearn-core-infrastructure-rg",
    "sku": null,
    "tags": {
      "Departement": "Finance",
      "Environment": "learn"
    },
    "type": "Microsoft.Network/virtualNetworks"
  },
  {
    "id": "/subscriptions/28b7bf82-0a7d-4ca7-9827-811c620d6d52/resourceGroups/msftlearn-core-infrastructure-rg/providers/Microsoft.Network/virtualNetworks/msftlearn-vnet2",
    "identity": null,
    "kind": null,
    "location": "switzerlandnorth",
    "managedBy": null,
    "name": "msftlearn-vnet2",
    "plan": null,
    "properties": null,
    "resourceGroup": "msftlearn-core-infrastructure-rg",
    "sku": null,
    "tags": {
      "Departement": "Marketing",
      "Environment": "learn"
    },
    "type": "Microsoft.Network/virtualNetworks"
  }
]

Is this a bug or does it have to be like this?


Solution

  • It is not a bug.

    The command az resource list --tag Departement=Finance essentially calls this REST API Resources - List with the $filter, you could use --debug in the command to check.

    az resource list --tag Departement=Finance --debug
    

    enter image description here

    The response will not include the tags property, so the tags will be null of the command result. You can also click the Try it button in this link, login to test with $filter directly.

    GET https://management.azure.com/subscriptions/xxxxxx/resources?api-version=2019-10-01&%24filter=tagName%20eq%20%27Departement%27%20and%20tagValue%20eq%20%27Finance%27
    

    enter image description here

    enter image description here


    When running az resource list --resource-group msftlearn-core-infrastructure-rg, it calls Resources - List By Resource Group, the tags will be included in the result.

    enter image description here