简体   繁体   中英

Delete all resources in a Google Cloud Project

One of my project contains many resources, which are created from different sources, means some from Deployment Manager API and some from Console by users.I need to delete all resources without deleting(shutting down) the project .In this case, is there any API endpoints which can delete all resources in this project including both created from Deployment Manager and Console?

I wrote Safe Scrub to do exactly that: Clean up resources from across Google Cloud, including GCE, AppEngine, GKE, CloudSQL, and more.

It has a focus on safety. For example, it does not actually delete any resources, but rather generates a script (a list of delete commands) that you can review and run.

Feedback is appreciated.

I don't think something like that exists, and it would be pretty dangerous if someone could just click on a button and shutdown/delete everything in a project, if you do a mistake with this you are in a position I don't want to think about.

A way to do what you want is something like a bash script that would use gcloud commands to delete what you need to delete.

Someone already tried but didn't go very far: https://github.com/enxebre/bazooka

Like night-gold said in the First Answer, right now there is no API endpoint to delete all resources inside a project.I discussed with a Google Cloud Engineer, and reply from him was:

"You will be able to delete the Deployment Manager resource by deleting the deployment itself. The resources created by a user through the console must be addressed individually. You can automate deleting the resources made by a user. Some suggested tools for accomplishing this would be to use Chef, Puppet, Ansible, Terraform, &/or shell scripts."

您可以使用部署 API 的列表方法来收集所有部署,然后使用删除方法删除部署和所有资源。

With the appropriate IAM config, here's how to delete all Endpoints for a given project :

#!/bin/bash
# 
# A script to delete all endpoints for a given project
# Usage: ./delete-endpoints.sh project-id

PROJECT=$1

ENDPOINTS=($(gcloud --project=${PROJECT} endpoints services list --format="value(serviceName)"))
for i in "${ENDPOINTS[@]}"
do
        gcloud -q endpoints services delete $i --async
done

Similar scripts can delete all kinds of resources using gcloud

In my project, we are using cats-love-money which is a simple script to remove pricey GCP resources (composers, GKEs, Dataprocs). By default, we remove everything older than 24h and without please-do-not-kill-me label.

It can be deployed on schedule using cloud functions and scheduler. It saves us a lot of cash.

Actually you can do this. Simply go to "IAM & Admin" -> "Manage Resources". This will take you to a management screen for your projects and you can delete them, see the billing, etc.

I wrote another project, Cloud Blaster to do exactly that: Clean up resources from across Google Cloud, including GCE, AppEngine, GKE, CloudSQL, and more.

Unlike my shell-script SafeScrub, mentioned in an answer above, this is in Kotlin and so is more flexible and robust to change.

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