01 Run compute instances describe command (Windows/macOS/Linux) using the name of the virtual machine (VM) instance that you want to re-create as identifier parameter (see Audit section part II to identify the right resource), to describe the configuration metadata available for the selected instance:
gcloud compute instances describe cc-internal-vm-instance
--zone us-central1-a
02 The command output should return the requested configuration information. This data will be used later to launch the new virtual machine instance:
cpuPlatform: Intel Haswell
deletionProtection: false
description: ''
disks:
- autoDelete: true
boot: true
deviceName: cc-internal-vm-instance
diskSizeGb: '100'
guestOsFeatures:
- type: UEFI_COMPATIBLE
- type: VIRTIO_SCSI_MULTIQUEUE
index: 0
interface: SCSI
kind: compute#attachedDisk
mode: READ_WRITE
source: https://www.googleapis.com/compute/v1/projects/cc-web-stack-project-123123/zones/us-central1-a/disks/cc-internal-vm-instance
type: PERSISTENT
displayDevice:
enableDisplay: false
...
name: cc-internal-vm-instance
reservationAffinity:
consumeReservationType: ANY_RESERVATION
scheduling:
automaticRestart: false
onHostMaintenance: TERMINATE
preemptible: true
shieldedInstanceConfig:
enableIntegrityMonitoring: true
enableSecureBoot: false
enableVtpm: true
shieldedInstanceIntegrityPolicy:
updateAutoLearnPolicy: true
startRestricted: false
status: RUNNING
tags:
items:
- http-server
- https-server
zone: https://www.googleapis.com/compute/v1/projects/cc-web-stack-project-123123/zones/us-central1-a
03 Run compute images create command (Windows/macOS/Linux) to create a machine image from the Google Compute Engine instance that you want to re-create. Include the --force flag to create the image from a running instance (by default, you cannot create images from running VM instances):
gcloud compute images create cc-internal-vm-image
--source-disk cc-internal-vm-instance
--source-disk-zone us-central1-a
--storage-location us-central1
--force
04 The command output should return the metadata for the newly created machine image:
Created [https://www.googleapis.com/compute/v1/projects/cc-web-stack-project-123123/global/images/cc-internal-vm-image].
NAME PROJECT FAMILY STATUS
cc-internal-vm-image cc-web-stack-project-123123 READY
05 Run compute instances create command (Windows/macOS/Linux) using the name of the machine image created at the previous steps and the configuration details returned at step no. 2 as configuration parameters, to create a new virtual machine (VM) instance from the selected image. To disable preemptibility for the new VM instance, avoid adding the --preemptible configuration parameter to the command request:
gcloud compute instances create cc-new-internal-vm-instance
--image-project=cc-web-stack-project-123123
--image=cc-internal-vm-image
--zone=us-central1-a
--machine-type=n1-standard-8
--restart-on-failure
--maintenance-policy=MIGRATE
06 The command output should return the metadata available for the new VM instance:
Created [https://www.googleapis.com/compute/v1/projects/cc-web-stack-project-123123/zones/us-central1-a/instances/cc-new-internal-vm-instance].
NAME ZONE MACHINE_TYPE INTERNAL_IP EXTERNAL_IP STATUS
cc-new-internal-vm-instance us-central1-a n1-standard-8 xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx RUNNING
07 To avoid unnecessary charges on your Google Cloud bill, you can remove the source (preemptible) instance from your GCP project. To remove the required VM instance, run compute instances delete command (Windows/macOS/Linux) using the name of the source instance that you want to remove as identifier parameter, to remove the selected resource from your GCP project:
gcloud compute instances delete cc-internal-vm-instance
--zone us-central1-a
08 Press Y at the command prompt to confirm the resource removal:
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.
- [cc-internal-vm-instance] in [us-central1-a]
Do you want to continue (Y/n)?
09 The command output should return the URL of the deleted VM instance:
Deleted [https://www.googleapis.com/compute/v1/projects/cc-web-stack-project-123123/zones/us-central1-a/instances/cc-internal-vm-instance].
10 Repeat steps no. 1 – 9 to disable preemptibility for other virtual machine instances available within the selected project.
11 Repeat steps no. 1 – 10 for each GCP project deployed within your Google Cloud account.