
When I test new ideas and features, I often rack up accidental cloud cost on Google Cloud Platform. I forget to delete things I created, and end up paying for resources that I kept running as a result.
Both methods presented here prevent further cost, but I recommend to use it on discardable projects only. There is a risk of losing one or more resources. So use at your own risk!!!
Two ways to stop the cost
There are two ways to stop accidental cloud cost on Google Cloud Platform:
- disable billing
- delete the project
disable billing
When you disable billing for the project, you will not incur any more cost. The documentation states that when you disable billing for a project, some resources might be removed and become non-recoverable.
To disable billing, type:
read -p "project id:" PROJECT_ID
BILLING_ACCOUNT=$(gcloud beta billing projects
describe $PROJECT_ID
--format 'value(billingAccountName)')
gcloud beta billing projects unlink $PROJECT_ID
To enable billing again, type:
gcloud beta billing projects
link $PROJECT_ID
--billing-account $BILLING_ACCOUNT
Again, it may take some time before resources are recovered and there is no guarantee that all resources will be recovered.
delete the project
When you delete the project all of its resources become unavailable and billing is disabled. But within a period of 30 days, you can restore the deleted project and most resources.
To delete the project, type:
gcloud projects delete $PROJECT_ID
To recover the project, type:
gcloud projects undelete $PROJECT_ID
gcloud billing projects
link $PROJECT_ID
--billing-account $BILLING_ACCOUNT
When you restore a project, it may take some time to recover the resources. The documentation states that some resources may be deleted before the 30 day period ends.
conclusion
To minimize accidental cloud cost on Google Cloud Platform, either disable billing or delete the project. Of the two methods, I prefer to disable billing. It is easier and there is no time limit on recovering the resources. But beware: there is no guarantee that all your resources will be recovered with either method. So only use this for projects for which you can take this risk, or for which you have a full disaster recovery process in place.
At least, it is far simpler than minimizing accidental cloud spend on AWS.
Image by 3D Animation Production Company from Pixabay