In this article, we’ll explain how to write bash script to launch VM in GCP.
Bash Script to Launch VM in GCP
Here is an example:
#!/bin/bash # Set the name of the VM VM_NAME="my-vm" # Set the zone where you want to create the VM ZONE="us-central1-a" # Set the machine type of the VM MACHINE_TYPE="n1-standard-1" # Set the image of the VM IMAGE_FAMILY="ubuntu-2004-lts" IMAGE_PROJECT="ubuntu-os-cloud" # Create the VM gcloud compute instances create $VM_NAME \ --zone $ZONE \ --machine-type $MACHINE_TYPE \ --image-family $IMAGE_FAMILY \ --image-project $IMAGE_PROJECT
This script sets the name of the VM, the zone where it will be created, the machine type, and the image. You can modify these variables to suit your needs.
To run the script, save it to a file (e.g., launch-vm.sh), make it executable (chmod +x launch-vm.sh), and then run it (./launch-vm.sh). The script will create a new VM with the specified settings in the specified zone.
End of article. We’ve explain how to create Bash Script to Launch VM in GCP.