Google Cloud Platform (GCP) Cheat Sheet
Essential gcloud CLI commands for managing projects, Compute Engine, storage, and IAM on Google Cloud Platform.
Auth & Project Config
Authenticate and configure the active project.
gcloud auth login # Browser-based logingcloud config set project my-project-id # Set default projectgcloud config list # Show current configgcloud projects list # List accessible projectsgcloud config set compute/zone us-central1-a
Compute Engine Instances
Create and manage VM instances.
gcloud compute instances create my-vm \ --machine-type=e2-medium --zone=us-central1-a \ --image-family=debian-12 --image-project=debian-cloudgcloud compute instances listgcloud compute instances stop my-vm --zone=us-central1-agcloud compute instances delete my-vm --zone=us-central1-agcloud compute ssh my-vm --zone=us-central1-a
Cloud Storage (gsutil / gcloud storage)
Manage buckets and objects.
gcloud storage buckets create gs://my-bucket --location=usgcloud storage cp ./file.txt gs://my-bucket/gcloud storage cp gs://my-bucket/file.txt ./gcloud storage ls gs://my-bucket/gcloud storage rm gs://my-bucket/file.txt
IAM & Services
Enable APIs and manage IAM bindings.
gcloud services enable compute.googleapis.comgcloud services list --enabledgcloud projects add-iam-policy-binding my-project-id \ --member="user:[email protected]" \ --role="roles/viewer"gcloud iam service-accounts create my-sa \ --display-name="My Service Account"
Core GCP Concepts
Key core gcp concepts to know.
- Project- Top-level container for GCP resources, billing, and IAM
- Region / Zone- Region is a geographic area; a zone is an isolated location within it
- Service Account- Non-human identity used by applications to call GCP APIs
- IAM Role- Bundle of permissions granted to a member (primitive, predefined, or custom)
- gcloud vs gsutil- 'gcloud storage' is the modern unified CLI replacing legacy 'gsutil' commands
Custom IAM Roles & Conditional Bindings
Define least-privilege custom roles and attach IAM conditions for time- or resource-scoped access.
gcloud iam roles create customStorageViewer \ --project=my-project-id \ --title="Custom Storage Viewer" \ --permissions=storage.objects.get,storage.objects.list \ --stage=GA# Bind with a condition (expires access, or scopes to a resource prefix)gcloud projects add-iam-policy-binding my-project-id \ --member="user:[email protected]" \ --role="projects/my-project-id/roles/customStorageViewer" \ --condition='expression=resource.name.startsWith("projects/_/buckets/reports-"),title=reports-only,expression-format=CEL'# Audit effective policy for a principalgcloud projects get-iam-policy my-project-id \ --flatten="bindings[].members" \ --filter="bindings.members:[email protected]" \ --format="table(bindings.role)"
Workload Identity Federation (Keyless Auth)
Let external workloads (CI/CD, other clouds) impersonate a service account without downloading a JSON key.
gcloud iam workload-identity-pools create github-pool \ --location=global --display-name="GitHub Actions Pool"gcloud iam workload-identity-pools providers create-oidc github-provider \ --location=global --workload-identity-pool=github-pool \ --issuer-uri="https://token.actions.githubusercontent.com" \ --attribute-mapping="google.subject=assertion.sub,attribute.repository=assertion.repository" \ --attribute-condition="assertion.repository=='my-org/my-repo'"gcloud iam service-accounts add-iam-policy-binding \ [email protected] \ --role="roles/iam.workloadIdentityUser" \ --member="principalSet://iam.googleapis.com/projects/123456/locations/global/workloadIdentityPools/github-pool/attribute.repository/my-org/my-repo"
Cloud Run: Deploy with Traffic Splitting
Ship a container revision behind a canary rollout instead of an all-at-once cutover.
gcloud run deploy my-service \ --image=us-central1-docker.pkg.dev/my-project-id/repo/my-service:v2 \ --region=us-central1 --no-traffic --tag=canary# Send 10% of live traffic to the new revision, keep 90% on stablegcloud run services update-traffic my-service \ --region=us-central1 \ --to-tags=canary=10 \ --to-latest=false# Promote once verifiedgcloud run services update-traffic my-service \ --region=us-central1 --to-latest
Terraform: GCP Provider Snippet
Manage GCP infrastructure declaratively instead of imperative gcloud calls.
provider "google" { project = "my-project-id" region = "us-central1"}resource "google_storage_bucket" "data" { name = "my-tf-bucket" location = "US" force_destroy = false uniform_bucket_level_access = true lifecycle_rule { condition { age = 30 } action { type = "SetStorageClass", storage_class = "NEARLINE" } }}resource "google_project_iam_member" "viewer" { project = "my-project-id" role = "roles/storage.objectViewer" member = "serviceAccount:${google_service_account.reader.email}"}
Advanced Operational Concepts
Terms that come up once you move past single-VM/single-bucket usage.
- Organization Policy Constraint- Org-wide guardrail (e.g. disable external IPs) enforced via 'gcloud resource-manager org-policies set-policy', overrides project-level IAM permissiveness
- VPC Service Controls- Perimeter around APIs (e.g. Storage, BigQuery) that blocks data exfiltration even with valid IAM credentials
- Shared VPC- Host project centrally owns the network; service projects attach and deploy resources into its subnets
- Cloud Build Trigger- CI pipeline defined in cloudbuild.yaml, fired on a source repo push, executed by ephemeral build workers
- Deployment Manager / Config Connector- Native IaC options; Config Connector manages GCP resources as Kubernetes CRDs for GitOps workflows
- Preemptible / Spot VM- Discounted Compute Engine instance that GCP can reclaim with short notice; use for fault-tolerant batch jobs
- Binary Authorization- Enforces that only signed/attested container images can deploy to GKE or Cloud Run
Use 'gcloud config configurations create' to maintain separate named configs (project, account, region) so you can switch contexts instantly with 'gcloud config configurations activate <name>'.