A No-Coder’s guide to using your Terminal & the gcloud CLI
Some Google Cloud Console operations are easier done (or only done) through the gcloud CLI (Command Line Interface). Unfortunately, for many of us in the low code / no code space, the command line is dangerous territory, and reserved for copy and paste from tutorials. This walkthrough takes you through the Command Line fundamentals for basic interactions with the gcloud CLI.
These are the things I find myself preferring the gcloud for over the Web Interface:
FYI - Examples will be using MacOS and the Mac Terminal.
Before doing anything practical you must first set a cool color theme for your terminal. An easy built-in theme is the Homebrew theme. Looks a little Matrix-like or green screen terminal from the 80’s
When you open a command line terminal, programs can be accessed by typing the program name. I use a lot of Node / npm (node package manager) for my serverless javascript work.
To get gcloud on your machine, you’ll need to follow this slightly tedious setup document from Google.
Things required:
cd ~
You can use the curl command to run web requests from the terminal. In the command below I call the curl command with a special flag (things with a dash in front are called flags and they are like specifying a certain setting or variable to pair with the command you called). I use the -O flag (case sensitive) to say I want to download the file in the current directory and leave the filename the same as specified in from the host of that file.
curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-455.0.0-darwin-arm.tar.gz
After running the command, you should see some outputs (text on screen) appear describing the download progress.
You’ll use the tar command with the -xvf flag followed by the name of the file relative to the current directory. This will finish with the original .gz file still in the directory along with a new directory called google-cloud-sdk.
You can learn more about unzipping things via Terminal here.
tar -xvf google-cloud-cli-455.0.0-darwin-arm.tar.gz
After the unzip, you should see google-cloud-sdk appear when you run an ls on the home directory.
Now you can rm (remove) the tar.gz file. Run the command below and then ls again. The tar.gz file should be tossed.
rm google-cloud-cli-455.0.0-darwin-arm.tar.gz
Now with the file unpacked, you can install all the components. The folder has an install shell script that we will call to make things easy. It will ask a few questions during install such as: Do you want to update your Python version (i said no), Do you want to update your PATH (I said yes and accepted the suggested path).
Run the command below from the Home directory (or whatever directory you downloaded the sdk into).
./google-cloud-sdk/install.sh
Once installed, you may need to close Terminal and reopen before you can run any gcloud commands.
If you foul up the install process for any reason, or simply want to get this program off your machine, just follow these official uninstall instructions from Google.
To get a sense for what you can do with gcloud, run the following command. Appending the --help flag to any gcloud command will display an explanation of what that command does and what flags/variables you can use to interact with it.
Go ahead and run this to get a 30,000ft view of what you can use gcloud for.
gcloud --help
Just like using GCP through the web console, the first thing you have to do is to Login with your Google Account. If you don’t have a Google Account, or have not logged into GCP (console.cloud.google.com) then go get an account setup.
After install, the first things you need to do in order to actually use this tool is noggin with your Google OAuth credentials. To see if you have any credentials stored on your machine, run this command to list them out.
gcloud auth list
If no credentials are present, run this gcloud auth login to initiate a browser based OAuth login session.
This automatically opens a browser session. However, this might not be ideal as it could conflict with certain browser profiles. If you navigate back to the Terminal session, you should see a long URL provided for you. Copy that and paste it in a browser where you’re already logged into that google account.
To start creating/modifying resources we first need to set up a Project to start working in. In this tutorial, I’m going to create a new project from scratch, but you could follow along in an existing project. Use gcloud projects list to see all available projects to your account. Copy the Project_ID from one of them and use gcloud config set project PROJECT_ID to set it as the current working project.
Create a new project by running:
gcloud projects create --name=test-proj --set-as-default
Accept the default project ID suggestion.
This should create the new project and set it as the current project you’re working on. Run this command to confirm:
gcloud config configurations list
You should see your current user listed and the Project ID you created as the current project associated to you.
With your User authenticated, and a Project selected, you can now fully manage your project and its resources from the command line. The CLI allows you to start automating various deployment or service tasks, and saving tons of time in your development efforts. Down below, I have some good boilerplate scripts for common GCP tasks.