是否有任何API可以获取我的Gcloud帐户中的所有资源

时间:2020-03-15 16:50:32

标签: google-cloud-platform google-api gcloud google-iam google-cloud-iam

我想通过API提取Gcloud帐户下的所有资源(VM实例,VPS,存储等),而不管项目和区域如何。

2 个答案:

答案 0 :(得分:3)

答案取决于您“我的Gcloud帐户”下所有资源的含义。

如果您对某个组织拥有cloudasset.assets.searchAllResources权限,则可以使用search-all-resources列出组织下的所有资源:

$ gcloud beta asset search-all-resources --scope=organizations/123

类似地,您可以使用相同的命令列出文件夹或项目的资源。

更多详细信息可以在另一篇文章中找到: How to find, list, or search resources across services (APIs) and projects in Google Cloud Platform?

答案 1 :(得分:1)

答案取决于您的“我的Gcloud帐户”是什么意思以及您的帐户凭据具有哪些权限(IAM角色)。

要列出您的凭据可以访问的所有Google Cloud项目中的所有资源,请使用resources CLI命令。请注意,这是alpha命令,还不是正式生产功能。此命令可能还需要Google列入白名单才能使用(我不确定此命令是否可用)。

gcloud alpha resources list --format json

gcloud alpha resources list

此命令是alpha功能,需要安装可选组件才能使用该命令。这需要提升(在Linux上为sudo):

gcloud components install alpha

gcloud components install

作为最后一步,我建议更新到最新的CLI版本。这需要提升(在Linux上为sudo):

gcloud components update

gcloud components update