Protect from Delete GCP project

gcloud projects delete one-click-tbd
Your project will be deleted.
Do you want to continue (Y/n)? YDeleted [https://cloudresourcemanager.googleapis.com/v1/projects/one-click-tbd].You can undo this operation for a limited period by running the command below.
$ gcloud projects undelete one-click-tbd
See https://cloud.google.com/resource-manager/docs/creating-managing-projects for information on shutting down projects.
gcloud alpha resource-manager liens create \
--restrictions=resourcemanager.projects.delete \
--reason="Super important production system"
Check that is applied:
gcloud alpha resource-manager liens list
NAME ORIGIN REASON
p151505267786-la6de8a11-573d-4724-8219-ed5a8669d2d2 user@companydomain.com Super important production system
gcloud projects delete one-click-not-tobedeleted 
Your project will be deleted.
Do you want to continue (Y/n)? YERROR: (gcloud.projects.delete) FAILED_PRECONDITION: Precondition check failed.
- '@type': type.googleapis.com/google.rpc.PreconditionFailure
violations:
- description: A lien to prevent deletion was placed on the project by [xpn.googleapis.com].
Remove the lien to allow deletion.
subject: liens/p151505267786-la6de8a11-573d-4724-8219-ed5a8669d2d2
type: LIEN
- '@type': type.googleapis.com/google.rpc.Help
links:
- description: Troubleshooting project deletion
url: https://cloud.google.com/resource-manager/docs/troubleshooting-project-deletion
- '@type': type.googleapis.com/google.rpc.ErrorInfo
domain: cloudresourcemanager.googleapis.com
reason: PROJECT_DELETE_LIEN

--

--

--

Working as Cloud Architect & Software enthusiastic

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

What Procurement Teams need to know about Agile

Learning to Code: Turning User Stories Into Code

HackTheBox — Bitlab

How to protect API keys with CMake in Android projects?

How to enable logging MongoDB queries for Spring Boot applications

Installing the Geospatial Data Abstraction Library (GDAL) in Python and Anaconda

A Look Back on the 3rd week of May in 2022 (5/16–5/22)

Implement a simple Operating System

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
NIRAV SHAH

NIRAV SHAH

Working as Cloud Architect & Software enthusiastic

More from Medium

Cloud Build with Docker and Dockerfile using dynamic environment variables

Helm & Kubernetes | Create Helm Charts

Jenkins CI/CD to update GCP MIG Instance using CloudBuild

A Threatmap for Log4Shell attacks on Google Cloud