Install GCP SDK

Here’s how to install Google Cloud Platform SDK on the following.

Centos, Fedora and Redhat

# Setup Repo
sudo tee -a /etc/yum.repos.d/google-cloud-sdk.repo << EOF
[google-cloud-sdk]
name=Google Cloud SDK
baseurl=https://packages.cloud.google.com/yum/repos/cloud-sdk-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
       https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
# Install
yum install google-cloud-sdk

For Debian, Ubuntu, Mint

# Create an environment variable for the correct distribution
export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)"
# Add the Cloud SDK distribution URI as a package source
echo "deb http://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" \
  | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
# Import the Google Cloud Platform public key
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg \
  | sudo apt-key add -
# Update the package list and install the Cloud SDK
sudo apt-get update && sudo apt-get install google-cloud-sdk

Google SDK Update

How to upgrade Google SDK on Redhat, Fedora and Centos Linux.

gcloud components update

If you are having trouble running that command because the GCloud component manager is disabled, you can try the following commands which will achieve the same result as above.

sudo yum makecache && sudo yum update \
kubectl \
google-cloud-sdk \
google-cloud-sdk-app-engine-grpc \
google-cloud-sdk-pubsub-emulator \
google-cloud-sdk-app-engine-go \
google-cloud-sdk-cloud-build-local \
google-cloud-sdk-datastore-emulator \
google-cloud-sdk-app-engine-python \
google-cloud-sdk-cbt \
google-cloud-sdk-bigtable-emulator \
google-cloud-sdk-datalab \
google-cloud-sdk-app-engine-java

GCP List Snapshots

Here are several examples how to display GCP snapshots using Google SDK (CLI – command line interface).

# list snapshots
gcloud compute snapshots list --project my-project --filter="name~'my-server-boot'"
# limit 10
gcloud compute snapshots list --project my-project --filter="name~'my-server-boot'" --limit 10
# reverse order
gcloud compute snapshots list --project my-project --filter="name~'my-server-boot'" --limit 10 --sort-by="~name"
# display uri
gcloud compute snapshots list --project my-project --filter="name~'my-server-boot'" --limit 10 --sort-by="~name" --uri

GCP Create Disk from Snapshot

Here’s how to create a disk from a snapshot via Google SDK.

gcloud compute disks create new-server-disk-2 \
--project=project-name \
--source-snapshot=server-disk-2 \
--zone=us-central1-b

GCP Instance Scopes

Give Instances access to other cloud services using scopes.

gcloud alpha compute instances set-scopes instance-name \
--project project-name --zone us-central1-a \
--scopes=cloud-platform,cloud-source-repos,compute-rw,storage-rw