简体   繁体   中英

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. 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 . 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)

An example of our python code

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM