01 Run compute instances describe command (Windows/macOS/Linux) with the name of the virtual machine (VM) instance that you want to re-create as the identifier parameter, to describe the configuration information available for the selected instance:
gcloud compute instances describe cc-backend-vm-instance
--zone us-central1-a
02 The command output should return the requested configuration information. This data will be used later to redeploy the selected instance:
cpuPlatform: Intel Haswell
deletionProtection: false
displayDevice:
enableDisplay: false
networkInterfaces:
- accessConfigs:
- kind: compute#accessConfig
name: External NAT
natIP: xxx.xxx.xxx.xxx
networkTier: PREMIUM
type: ONE_TO_ONE_NAT
kind: compute#networkInterface
name: nic0
network: https://www.googleapis.com/compute/v1/projects/cc-web-stack-project-123123/global/networks/default
networkIP: 10.128.0.10
stackType: IPV4_ONLY
subnetwork: https://www.googleapis.com/compute/v1/projects/cc-web-stack-project-123123/regions/us-central1/subnetworks/default
...
- accessConfigs:
- kind: compute#accessConfig
name: External NAT
natIP: xxx.xxx.xxx.xxx
networkTier: PREMIUM
type: ONE_TO_ONE_NAT
kind: compute#networkInterface
name: nic1
network: https://www.googleapis.com/compute/v1/projects/cc-web-stack-project-123123/global/networks/cc-custom-vpc
networkIP: 10.0.0.2
stackType: IPV4_ONLY
subnetwork: https://www.googleapis.com/compute/v1/projects/cc-web-stack-project-123123/regions/us-central1/subnetworks/tm-central
kind: compute#instance
machineType: https://www.googleapis.com/compute/v1/projects/cc-web-stack-project-123123/zones/us-central1-a/machineTypes/n1-standard-8
name: cc-backend-vm-instance
enableIntegrityMonitoring: true
enableSecureBoot: false
enableVtpm: true
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:
gcloud compute images create cc-backend-vm-instance-image
--source-disk cc-backend-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-backend-vm-instance-image].
NAME PROJECT FAMILY DEPRECATED STATUS
cc-backend-vm-instance-image cc-web-stack-project-123123 READY
05 Run compute instances create command (Windows/macOS/Linux) with the name of the machine image created at the previous steps and the configuration details returned at step no. 2 as the configuration parameters, to create a new virtual machine (VM) instance from the selected image. For example, the following command creates a new VM instance with only one network interface, specified by the --network-interface parameter:
gcloud compute instances create cc-new-backend-instance
--image-project=cc-web-stack-project-123123
--image=cc-backend-vm-instance-image
--zone=us-central1-a
--machine-type=n1-standard-8
--network-interface network=cc-custom-vpc,subnet=subnet-central,private-network-ip=10.0.0.1,no-address
06 The command output should return the information 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-backend-instance].
NAME ZONE MACHINE_TYPE INTERNAL_IP EXTERNAL_IP STATUS
cc-new-production-instance us-central1-a n1-standard-8 10.128.0.10 xxx.xxx.xxx.xxx RUNNING
07 (Optional) To avoid extra charges on your monthly bill, you can remove the source (non-compliant) instance from your GCP project. To remove the instance, run compute instances delete command (Windows/macOS/Linux) with the name of the source (non-compliant) instance that you want to remove as the identifier parameter, to remove the selected compute resource from your project:
gcloud compute instances delete cc-backend-vm-instance
--zone us-central1-a
08 Type Y and press Enter 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-backend-vm-instance] in [us-central1-a]
Do you want to continue (Y/n)? Y
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-backend-vm-instance].
10 Repeat steps no. 1 – 9 for each non-compliant VM instance that you want to relaunch, available in the selected project.
11 Repeat steps no. 1 – 10 for each GCP project deployed in your Google Cloud account.