Skip to content
Beginner CloudLesson 7 of 13 3 min read

The gcloud CLI

Install-once, use-everywhere: gcloud init, properties, configurations, output formats, and release levels.

On this page8 sections

The Google Cloud CLI is the command-line tool for creating and managing Google Cloud resources. Anything you can click in the console you can script with gcloud, which is what makes it the backbone of automation, CI pipelines, and runbooks.

How commands are shaped

Commands are a tree of groups that mirror Google Cloud products, ending in a verb:

gcloud  compute  instances  create  web-1  --zone=us-central1-a
        └ group  └ group    └ verb  └ arg  └ flag

Once you know the pattern, you can guess most commands: gcloud storage buckets list, gcloud run services describe, gcloud container clusters delete. Add --help to anything to see its manual.

First-time setup

bash
gcloud init

gcloud init signs you in through a browser, picks a project, and optionally sets a default region and zone. To check who you are signed in as:

bash
gcloud auth list

Properties

gcloud remembers settings as properties, grouped into sections. The ones you will set most often:

PropertyWhat it does
core/projectThe project every command acts on
compute/regionDefault region for regional resources
compute/zoneDefault zone for zonal resources such as VMs
bash
gcloud config set project learninx-demo
gcloud config set compute/region us-central1
gcloud config set compute/zone us-central1-a
gcloud config list
gcloud config get project

Any property can be overridden for one command with a flag, for example --project=other-project or --zone=europe-west1-b. Scripts usually pass flags explicitly so they never depend on whoever ran gcloud config set last.

Configurations

A configuration is a named set of properties, like a profile. The default configuration is enough for most people. If you juggle several projects or accounts, gcloud config configurations create staging gives you a second profile, and gcloud config configurations activate staging switches to it.

Output formats

Human-readable tables are the default. For scripts, ask for something machine-readable with --format:

bash
gcloud compute instances list --format=json
gcloud compute instances list --format="value(name,status)"

value(...) prints bare values with no header. That is ideal for piping into while read loops or xargs.

Release levels

Commands ship at different maturity levels. GA (general availability) commands are production-ready. Beta commands are functionally complete but may still change. Alpha commands are early and can change without notice. You reach them with gcloud beta ... and gcloud alpha ....

Try it

Run these in the practice terminal (opens in a new tab). It opens in a new tab, so you keep your place here.
bash
gcloud --version
gcloud auth list
gcloud config set compute/zone us-central1-a
gcloud config list

When you're ready, hit Mark complete and move to the next lesson.

Further reading

Challenge

Set the default Compute Engine zone to us-central1-a, so zonal commands stop asking for --zone.

Want to experiment first? Try things in the practice terminal (opens in a new tab), then enter the command that solves the task here.

Quiz

Lock in the concepts. Score at least 80% to mark the lesson complete.

0 of 3 answered

Done with this one?

Skipped the challenge? You can mark the lesson complete by hand.

Your notes

Kept on this browser only.