简体   繁体   English

如何以编程方式删除 GCP 资源文件夹?

[英]How to delete a GCP Resource Folder programatically?

I am trying to create a cron service that cleans up (removes billing and deletes) a bunch of projects and resource folders on GCP for a development team.我正在尝试创建一个 cron 服务,为开发团队清理(删除计费和删除)GCP 上的一堆项目和资源文件夹。 Ideally, I would like to use cloud functions to do this as its lightweight, however, I can't seem to find any client libraries that would allow for FOLDER deletion .理想情况下,我想使用云功能来执行此操作,因为它是轻量级的,但是,我似乎找不到任何允许删除 FOLDER 的客户端库 Has anyone been able to find any client libraries to do this?有没有人能够找到任何客户端库来执行此操作?

The other options I am considering are:我正在考虑的其他选择是:

You can use the discovery API. We use it in production (only for search and then attach project to a folder)您可以使用发现 API。我们在生产中使用它(仅用于搜索,然后将项目附加到文件夹)

An example of our python code我们的 python 代码示例

from googleapiclient import discovery 
from oauth2client.client import GoogleCredentials

#Use GCF Service Account credentials for all APIs call
CREDENTIALS = GoogleCredentials.get_application_default()

SERVICE_RESOURCE_MANAGER_FOLDER = discovery.build('cloudresourcemanager', 'v2', 
                                                    credentials=CREDENTIALS)

# Example for a search
    request = SERVICE_RESOURCE_MANAGER_FOLDER.folders().search(body=body)
    response = request.execute()

Use the delete operation if you want to do this.如果要执行此操作,请使用删除操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PHP - 如何删除 GCP 存储桶文件夹及其中的所有文件/文件夹? - PHP - How can I delete a GCP bucket folder and all files/folders within it? 如何重置(删除)存储桶的 CORS 设置? (全球控制点) - How to reset(delete) CORS settings for a bucket? (GCP) 如何删除 Cloud Run (GCP) 上的最新修订版 - How to delete the latest revision on Cloud Run (GCP) 如何使用 API 在 GCP Bucket 中创建文件夹? - How to create a folder in the GCP Bucket using API? 如何使用 python 将文件夹从本地上传到 GCP 存储桶 - How to upload folder from local to GCP bucket using python 如何将我的项目添加到多个 GCP 资源位置? - How to add my project to multiple GCP resource locations? 如何使用 gcloud 命令工具将 GCP IAM 策略附加到资源? - How attach a GCP IAM policy to a resource with gcloud command tool? 如何列出/获取项目中所有 GCP 资源的“创建者”? - How to list/get the 'creator' of all GCP resource in a project? 如何从 GCP Cloud Function 中的 maven 资源文件夹中读取文件? - How to read a file from maven resources folder in GCP Cloud Function? 如何在 Terraform(对于 GCP)中引用现有组织文件夹或其他资源 - How to reference an existing organization folder, or other resources, in Terraform (For GCP)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM