deleting all resources inside project

2,788 views
Skip to first unread message

Alberto García Lamela

unread,
Oct 19, 2017, 6:00:25 AM10/19/17
to gce-discussion
I need to create short-living infrastructure groups so I need to effectively clean/garbage collect the resources regularly.
One possible solution I thought of is to use Projects as the atomic resource so creating and destroying projects continuously which seems overkill, as I might need permanent dns config, and projects still count for the quota after shut them down.

Is there any other way to effectively and "easily" clean all the resources inside a given project using the cli/gcloud?
Thanks!

A Holbreich

unread,
Oct 19, 2017, 11:20:53 AM10/19/17
to gce-discussion
Then you should automate things

Some alternatives i see:

- terraform (i would go with)
- ansible
- or scripting with google cli

Taher (Cloud Platform Support)

unread,
Oct 19, 2017, 4:54:48 PM10/19/17
to gce-discussion

Hello Alberto,


You might want to consider using the Cloud Deployment Manager. It allows you to deploy resources and clean them up when you are done with them. Whichever resources are not required to be disposable, can be excluded from the deployment configuration. This way DNS configuration can also be kept as is.


Deleting a deployment allows you to easily clean up all the resources which are part of it, removing the need to delete the project to clean up. The deletion can be done by Console, Gcloud command and also via API.

Alberto García Lamela

unread,
Oct 23, 2017, 11:41:20 AM10/23/17
to gce-discussion
Hi Taher,
is there any standard way to generate a deployment config file from a project already running on GCE?
Thanks,
Alberto

Taher (Cloud Platform Support)

unread,
Oct 24, 2017, 11:06:34 AM10/24/17
to gce-discussion

Hi Alberto,


You might want to submit a new feature request to achieve this task as there is no direct way to generate a deployment config from a running project yet. However, you can consider using a template as a workaround which will consist the required resources which can be used to make the configuration in deployment manager later on.

Alberto García Lamela

unread,
Oct 30, 2017, 1:05:54 PM10/30/17
to gce-discussion
Created this as a starting point https://github.com/enxebre/bazooka
Message has been deleted

Akash P

unread,
Sep 19, 2018, 9:48:22 AM9/19/18
to gce-discussion
Hi Taher

Suppose project includes two kinds of resources, i mean those created by Cloud Deployment Manager and those created from Console by a User. In this case, is there any API endpoints to delete all the resource under this Project?

Thanks
Akash

xchri...@google.com

unread,
Sep 21, 2018, 2:45:17 PM9/21/18
to gce-dis...@googlegroups.com
Hi Akash,

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.

I will note that these software products are suggestions from an individual, & do not reflect Google's alignment with any of these companies. 

Justin Reiners

unread,
Sep 21, 2018, 3:08:42 PM9/21/18
to xchri...@google.com, gce-discussion
this can be done through gcloud api fairly easily

do not run this without knowing what it does, it's an example, although it should work for you out of the box. These will destroy your data without recovery.

compute engine:
gcloud compute instances list | cut -f 1 -d ' ' | while read line; do gcloud compute instances delete $line --delete-disks ;done

all snapshots:
gcloud compute snapshots list |cut -f 1 -d " " | while read line; do gcloud compute snapshots delete $line --quiet ;done

sql servers:
gcloud sql instances list | cut -f 1 -d ' ' | while read line; done gcloud sql instances delete $line

if you need more help, just let me know. I recommend you take a look at the gcloud api info

On Fri, Sep 21, 2018 at 1:45 PM xchristian via gce-discussion <gce-dis...@googlegroups.com> wrote:
Hi Akashn,

--
© 2018 Google Inc. 1600 Amphitheatre Parkway, Mountain View, CA 94043
 
Email preferences: You received this email because you signed up for the Google Compute Engine Discussion Google Group (gce-dis...@googlegroups.com) to participate in discussions with other members of the Google Compute Engine community and the Google Compute Engine Team.
---
You received this message because you are subscribed to the Google Groups "gce-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gce-discussio...@googlegroups.com.
To post to this group, send email to gce-dis...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gce-discussion/50a88e65-8ba8-4966-8274-2c568685cef1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Justin Reiners

unread,
Sep 21, 2018, 5:04:02 PM9/21/18
to xchri...@google.com, gce-discussion
sorry the sql one should be : gcloud sql instances list | cut -f 1 -d ' ' | while read line; do gcloud sql instances delete $line
Reply all
Reply to author
Forward
0 new messages