Skip to content

Instantly share code, notes, and snippets.

@TiagoGouvea
Last active May 2, 2020 13:47
Show Gist options
  • Save TiagoGouvea/6b64d8b91f7ff819815b2f6a658d2c4e to your computer and use it in GitHub Desktop.
Save TiagoGouvea/6b64d8b91f7ff819815b2f6a658d2c4e to your computer and use it in GitHub Desktop.
Sample script to create a Google Compute Engine VM instance
#!/usr/bin/env bash
echo -e "\nCreate remote instance"
echo -e "\n# 1/2 - Loading and setting options..."
## Show commands (if you want to check, uncomment it)
#set -x
## Stop on errors
set -e
## Include config
source config.sh
## Set GCP compute zone
gcloud config set project ${PROJECT}
gcloud config set compute/zone ${ZONE}
## Create instance
echo -e "\n# 1/2 - Creating Compute Instance..."
gcloud compute instances create ${INSTANCE_NAME} \
--image-family ${IMAGE_FAMILY} \
--image-project ${IMAGE_PROJECT} \
--machine-type ${MACHINE_TYPE} \
--zone ${ZONE} \
--tags ${TAGS} \
--${DELETION_PROTECTION}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment