gcloud cheat sheet

Brian Suk
Google Cloud - Community
1 min readMar 30, 2022

--

No big insights or a story to tell. Just a list of gcloud commands that I constantly find myself searching for and figured I’d keep it in one place that’s public and accessible.

This will constantly be added to. And remember, it’s in the context of whatever project you’re logged into via gcloud init so check that too so you’re not getting unexpected results.

General Project Stuff

Who am I logged in as?
gcloud auth list

What is my project name?
gcloud config get-value project

What is my project number?
gcloud projects list --filter="$(gcloud config get-value project)" --format="value(PROJECT_NUMBER)"

What is my project ID?
gcloud config get-value project

Billing

Get all my billing accounts into CSV.
gcloud alpha billing accounts list --format="csv(displayName,masterBillingAccount,name,open)" > billingAccounts.csv

IAM

Add secret.mangaer/secretAccessor to my Cloud Build Service Account.
gcloud projects add-iam-policy-binding $(gcloud config get-value project) --member=serviceAccount:"$(gcloud projects list --filter="$(gcloud config get-value project)" --format="value(PROJECT_NUMBER)")@cloudbuild.gserviceaccount.com" --role=roles/secretmanager.secretAccessor

Add roles/cloudfunctions.invoker to a BigQuery generated service account for a remote connection.

Neat Stuff

Generate Terraform HCL for my infrastructure.
gcloud alpha resource-config bulk-export --resource-format=terraform > allstuff.tf

Get the name of a VM with the name that matches a substring.
gcloud compute instances list --filter="my_partial_string-" --format="value(NAME)"

--

--

Brian Suk
Google Cloud - Community

Avid 2020 bed-to-couch traveler, cloud tech, big data, random trivia, Xoogler. My employer isn’t responsible for what’s here. NYC. linkedin.com/in/briansuk