Reputation: 125
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?
Upvotes: 6
Views: 18931
Reputation: 19695
I wrote Safe Scrub to do exactly that: Clean up resources from across Google Cloud, including GCE, AppEngine, GKE, CloudSQL, and more.
New: See my newer project CloudBlaster, mentioned in an answer below. CloudBlaster is in Kotlin and so is more flexible and robust to change. However, SafeScrub has the advantage of writing a shell script to do the actual deletion, giving you a sense of security in directly controlling the deletion code you run.
Upvotes: 4
Reputation: 19695
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.
Upvotes: 0
Reputation: 59
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.
Upvotes: 5
Reputation: 808
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.
Upvotes: 0
Reputation: 750
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
Upvotes: 0
Reputation: 125
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."
Upvotes: 1
Reputation: 576
You can use Deployment API's list method to gather all deployments then the delete method which will remove the deployments and all of the resources.
Upvotes: 0
Reputation: 2441
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
Upvotes: 1