
Wagner Bianchi
Hello Folks,
It happened to me and maybe can happen with you as well. During this lecture, Mattias lines out how to protect the instance for an accidental deletion – also he says it’s not the correct way of doing this, to use firewall rules and the right permissions instead. Right after that, he creates an instance and SSH into it. Finally, he asks to delete the instance and then:
$ gcloud compute instances delete myverysuperhappyvm Did you mean zone [us-east1-b] for instance: [myverysuperhappyvm] (Y/n)? Y The following instances will be deleted. Any attached disks configured to be auto-deleted will be deleted unless they are attached to any other instances or the `--keep-disks` flag is given and specifies them for keeping. Deleting a disk is irreversible and any data on the disk will be lost. - [myverysuperhappyvm] in [us-east1-b] Do you want to continue (Y/n)? Y ERROR: (gcloud.compute.instances.delete) Could not fetch resource: - Invalid resource usage: 'Resource cannot be deleted if it's protected against deletion.'.
Ok, to know how to deal with a real situation, I researched a little bit and decided to place the quick solution for you here. Of course, to bypass the deletion protection of an instance, you must know well what you doing when working on a production environment.
$ gcloud compute instances update myverysuperhappyvm --no-deletion-protection Did you mean zone [us-east1-b] for instance: [myverysuperhappyvm] (Y/n)? Y Setting deletion protection of instance [myverysuperhappyvm] to [False]...done. $ gcloud compute instances delete myverysuperhappyvm Did you mean zone [us-east1-b] for instance: [myverysuperhappyvm] (Y/n)? Y The following instances will be deleted. Any attached disks configured to be auto-deleted will be deleted unless they are attached to any other instances or the `--keep-disks` flag is given and specifies them for keeping. Deleting a disk is irreversible and any data on the disk will be lost. - [myverysuperhappyvm] in [us-east1-b] Do you want to continue (Y/n)? Y Deleted [https://www.googleapis.com/compute/v1/projects/service-exploration-labs-20430/zones/us-east1-b/instances/myverysuperhappyvm].
I hope it helps!
-Bianchi