Search code examples
google-cloud-platformgcloud

How to delete GCP project immediately?


We are planning for some GCP events and wanted to give each user a separate Google Cloud project to play. Billing will be charged to a single master account and after the event, all projects should be deleted to stop billing.

I didn’t want to do it manually, so I scripted it. I am using gcloud to create, assign roles and delete the projects (after the event).

gcloud  projects create $PROJECT_ID

gcloud projects delete $PROJECT_ID

With this command, projects are deleting but it is only soft delete. GCP will delete these projects after 30 days.

I am writing some cleaning scripts to delete all the resources from the project before deleting the project so that it will not cost me the 30 days charge but it's too much of work.

Is there any way to delete the GCP projects immediately?


Solution

  • According to the doc Shutting down (deleting) projects,

    The project is marked for deletion ("soft deleted"), and you will lose access to it immediately, but the project can be recovered for a 30 day period. Until actual detention of the project, the project will count towards your quota usage

    No, you cannot delete the GCP projects immediately. And as the docs says:

    If billing is set up for a project, it might not be completely deleted until the current billing cycle ends and your account is successfully charged

    I think the best solution is to disable your billing from the projects you want to delete. So it won't be charge for the resource you didn't use, and after 30 days GCP will automatically remove the projects for you. As for disable the billing, this can only be done manually.

    Out of curiosity, why do you need to give each user a project to use? Any specific purposes? Why can't you just let them use the same project, and give them different roles? You can set up Custom Roles now, so you won't need to manage all these projects.

    Hope this helps.