0

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

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

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

4

1 回答 1

0

这不是一个错误。

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

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

在此处输入图像描述

响应将不包含该tags属性,因此tags命令结果将为 null。您也可以点击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 Grouptags将包含在结果中。

在此处输入图像描述

于 2020-01-28T08:12:33.410 回答