天蓝色:az 资源列表缺少标签

azure: az resource list missing tags

如果我用 az resource list --tag Departement=Finance

列出我的资源,它告诉我我有 null 标签
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"
  }
]

但是 az resource list --resource-group msftlearn-core-infrastructure-rg 它显示了所有标签。

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"
  }
]

这是一个错误还是必须这样?

这不是错误。

命令 az resource list --tag Departement=Finance 本质上是用 $filter 调用此 REST API Resources - List,您可以在命令中使用 --debug 来检查。

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

响应将不包含 tags 属性,因此 tags 将为空的命令结果。您也可以点击link中的Try it按钮,直接用$filter登录测试

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


当运行az resource list --resource-group msftlearn-core-infrastructure-rg调用Resources - List By Resource Group时,tags会被包含在结果中。