← All tutorials
GCP Services & IaC

GCP services & Infrastructure as Code

Google Cloud gives you the same building blocks as any hyperscaler β€” compute, storage, databases, data pipelines, networking, AI β€” but its real strengths are data analytics (BigQuery), containers (GKE, Cloud Run) and ML (Vertex AI). And however you build, you should define it in code, not clicks. This guide tours the core GCP services, then introduces Infrastructure as Code to provision them repeatably.

Two halves. First, a field guide to the services worth knowing and what each solves. Second, how to create them β€” not by clicking in the console (which drifts and can't be reviewed) but declaratively with IaC, mainly Terraform. The companion AWS field guide and Cloud Native tutorials pair well with this.

Foundations  The GCP resource hierarchy

Before services, learn how GCP organises them β€” it drives billing, IAM and blast radius. Everything lives in a tree:

LevelWhat it is
OrganizationRoot node tied to your domain β€” company-wide policies live here.
FolderOptional grouping (by department, team, or environment).
ProjectThe core unit β€” every resource belongs to exactly one project; it's the boundary for billing, quota, IAM & APIs.
ResourcesThe actual services (a VM, a bucket, a database) inside a project.

Two more concepts you'll meet constantly:

Where it runs

Regions & zones

A region (e.g. us-central1) is a geographic area; a zone (us-central1-a) is one datacenter within it. Spread across zones for HA.

Who can do what

IAM

Grant roles (bundles of permissions) to principals (users, groups, service accounts) on a resource. Service accounts are the identity your workloads use.

Rule of thumb: one project per app per environment (e.g. shop-prod, shop-staging). It cleanly isolates billing, quotas and permissions β€” and maps neatly onto separate IaC state.

Field guide  Core services by category

The services most teams actually reach for, grouped by the problem they solve.

βš™οΈ Compute β€” run your code

ServiceSolvesReach for it when…
Compute EngineVMs (IaaS)You need full control of the OS, GPUs, or a lift-and-shift.
Cloud RunServerless containersYou have a container and want it to scale to zero with no cluster to manage. The GCP sweet spot.
GKEManaged KubernetesYou need full Kubernetes β€” many services, complex networking, portability. See Cloud Native.
Cloud FunctionsEvent-driven functions (FaaS)Small snippets triggered by an event (a file upload, a Pub/Sub message).
App EngineManaged app platform (PaaS)You want to push code and let Google run it β€” the original GCP PaaS.

πŸ—„οΈ Storage & databases β€” keep your data

ServiceSolvesReach for it when…
Cloud StorageObject storageFiles, images, backups, static assets, data-lake landing zone (the S3 equivalent).
Cloud SQLManaged Postgres / MySQL / SQL ServerA standard relational DB without running the server yourself. (Pairs with the Postgres performance guide.)
AlloyDBPostgres-compatible, high-performanceYou've outgrown Cloud SQL and want Postgres with more throughput/analytics.
SpannerGlobally-distributed relationalYou need horizontal scale and strong consistency across regions.
FirestoreServerless document NoSQLMobile/web apps needing realtime sync and flexible documents.
BigtableWide-column NoSQL at massive scaleHigh-throughput time-series, IoT, or analytics key-value workloads.
MemorystoreManaged Redis / MemcachedCaching and low-latency in-memory data.

πŸ“Š Data & analytics β€” GCP's crown jewels

ServiceSolvesReach for it when…
BigQueryServerless data warehouseAnalytical SQL over terabytes–petabytes with no infra. GCP's flagship β€” often the reason teams pick GCP.
Pub/SubGlobal messaging / streamingDecouple producers & consumers; ingest event streams (SNS+SQS/Kinesis in one).
DataflowManaged Apache Beam pipelinesStream or batch ETL that autoscales.
DataprocManaged Spark / HadoopYou have existing Spark/Hadoop jobs to run.

🌐 Networking Β· πŸ€– AI Β· πŸ”§ Operations

ServiceSolves
VPCYour private, global software-defined network (subnets, firewall, routing).
Cloud Load BalancingGlobal anycast L4/L7 load balancing behind one IP.
Cloud CDN / Cloud DNSEdge caching and managed DNS.
Vertex AIEnd-to-end ML platform: train, tune, deploy, plus the Gemini API. (See Google agent patterns.)
Cloud Logging / MonitoringThe observability stack (formerly Stackdriver) β€” logs, metrics, traces, alerts.
Secret ManagerStore & version secrets (API keys, DB passwords) with IAM access.
IAMWho can do what, on which resource β€” the control plane for everything.
If you remember five: Cloud Run (run containers), Cloud Storage (files), Cloud SQL (relational DB), BigQuery (analytics), Pub/Sub (messaging). That covers a large share of real GCP apps.

Translation  GCP ↔ AWS quick map

Already know AWS? Map the mental model across. Equivalents are approximate, not identical.

CategoryGCPAWS
VMsCompute EngineEC2
Serverless containersCloud RunFargate / App Runner
KubernetesGKEEKS
Functions (FaaS)Cloud FunctionsLambda
Object storageCloud StorageS3
Managed relationalCloud SQLRDS
Global relationalSpannerAurora (β‰ˆ) / DynamoDB Global
Document NoSQLFirestoreDynamoDB
Data warehouseBigQueryRedshift / Athena
Messaging / streamingPub/SubSNS + SQS / Kinesis
ML platformVertex AISageMaker / Bedrock
SecretsSecret ManagerSecrets Manager
IdentityIAMIAM

Second half  What is Infrastructure as Code?

Infrastructure as Code (IaC) means defining your cloud resources β€” VMs, buckets, databases, networks, IAM β€” in text files under version control, and letting a tool create and update them to match. You describe the desired state; the tool figures out the API calls.

The problem it solves

Click-ops

Drift & snowflakes

Consoles create one-off "snowflake" environments no one can reproduce. Staging never quite matches prod.

No history

No review, no audit

A click leaves no diff, no PR, no reviewer. Who opened that firewall port, and when?

Manual

Slow & error-prone

Rebuilding an environment by hand takes days and misses steps. Disaster recovery is a prayer.

Declarative vs imperative. IaC is usually declarative: you state the end result (“a bucket named X in region Y”) and the tool reconciles reality to it β€” creating, updating, or deleting as needed. An imperative script (a pile of gcloud commands) lists steps and can't tell what already exists. Declarative is idempotent: run it twice, get the same result.
What you get: reproducible environments (spin up an identical stack in minutes) Β· code review & audit for every infra change Β· easy rollback (revert the commit) Β· self-documenting infrastructure Β· consistent dev/staging/prod from the same modules.

Options  IaC tools for GCP

ToolWhat it isUse when…
Terraform / OpenTofuDeclarative, cloud-agnostic (HCL). The de-facto standard; OpenTofu is the open-source fork.Almost always β€” largest ecosystem, multi-cloud, huge module registry.
Config ConnectorManage GCP resources as Kubernetes objects (KRM).You're all-in on GKE and want GitOps via Kubernetes tooling.
PulumiIaC in real languages (TypeScript, Python, Go).Your team prefers a general-purpose language and loops/abstractions over HCL.
gcloud CLI / scriptsImperative commands.Quick experiments & exploration β€” not durable infrastructure (no state, drifts).
Deployment ManagerGCP's native (legacy) IaC.Rarely for new work β€” Google steers toward Terraform now.
The gcloud trap: shell scripts of gcloud commands feel like IaC but aren't β€” there's no state file, so the tool can't detect drift, plan a diff, or safely delete what you removed. Use gcloud to explore; use Terraform to own infrastructure.

Hands-on  Terraform on GCP β€” a walkthrough

Terraform's loop is write β†’ plan β†’ apply, with a state file recording what it manages so it can compute the diff between your code and reality.

The Terraform workflow You write HCL, run terraform plan to preview the diff, review it (ideally in a pull request), then terraform apply provisions GCP and records the result in state. Write HCL.tf files planpreview diff Review / PRapprove change applyprovision GCP ☁️ GCP πŸ“„ state records reality

1 Β· Configure the provider

# main.tf β€” tell Terraform to manage GCP
terraform {
  required_providers {
    google = { source = "hashicorp/google", version = "~> 5.0" }
  }
  # Remote, locked state in a GCS bucket (see best practices)
  backend "gcs" { bucket = "my-tfstate", prefix = "shop/prod" }
}

provider "google" {
  project = "shop-prod"
  region  = "us-central1"
}

2 Β· Declare resources

# A bucket and a Cloud Run service β€” the desired state
resource "google_storage_bucket" "assets" {
  name          = "shop-prod-assets"
  location      = "US"
  force_destroy = false
}

resource "google_cloud_run_v2_service" "api" {
  name     = "shop-api"
  location = "us-central1"
  template {
    containers { image = "us-docker.pkg.dev/shop-prod/app/api:1.4.0" }
  }
}

3 Β· Plan, then apply

terraform init      # download providers, wire up the backend
terraform plan      # preview: what will be created/changed/destroyed
terraform apply     # make it so; records outcome in state

# Example plan summary:
Plan: 2 to add, 0 to change, 0 to destroy.
Always read the plan. Before apply, scan for destroy lines β€” Terraform will happily replace a database if a change forces it. In CI, run plan on the PR and require human approval before apply.

4 Β· Reuse with variables & modules

# Same module, different envs β€” no copy-paste
module "service" {
  source = "./modules/cloud-run-api"
  env    = var.env        # "staging" or "prod"
  image  = var.image
}

Do it right  IaC best practices

PracticeWhy
Remote state + lockingStore state in a GCS backend, not on a laptop. Locking stops two people applying at once and corrupting it.
Plan in CI, apply on approvalEvery change is a reviewed PR with a plan attached β€” no surprise applys.
No secrets in codeReference Secret Manager; never hard-code keys. State can contain secrets β€” encrypt & lock it down.
Modules for reuseOne tested module per pattern; compose environments from it instead of copy-paste.
Separate state per environmentIsolate prod from staging so a mistake can't cross the boundary.
Least-privilege service accountThe CI identity that runs Terraform gets only the roles it needs. See security.
Detect driftRun plan on a schedule; a non-empty diff means someone click-opped β€” reconcile it.
The mindset: the console is read-only. If a change isn't in a merged commit, it didn't happen β€” and it'll be reverted on the next apply. That single discipline is what makes infrastructure reproducible, reviewable and recoverable.

Cheat sheet

QuestionShort answer
Core unit of GCP org?The project β€” billing, quota, IAM & API boundary.
Run a container serverless?Cloud Run. Full Kubernetes? GKE. A VM? Compute Engine.
GCP's flagship service?BigQuery β€” serverless analytics warehouse.
S3 / RDS / Lambda on GCP?Cloud Storage / Cloud SQL / Cloud Functions.
What is IaC?Define infra as version-controlled code; a tool reconciles reality to the desired state.
Declarative vs imperative?Declarative = state the goal (idempotent); imperative = list steps (gcloud script).
Default IaC tool for GCP?Terraform / OpenTofu.
Terraform loop?write β†’ plan β†’ review β†’ apply, with remote state.
Is a gcloud script IaC?No β€” no state, so no drift detection or safe diffing.

Knowledge check

Six questions. Pick an answer for each, then check your score.

1. What is the core organisational unit in GCP β€” the boundary for billing, quota and IAM?

2. You have a container and want it to scale to zero with no cluster to manage. Best fit?

3. Which GCP service is the serverless data warehouse (β‰ˆ Redshift/Athena)?

4. What best describes Infrastructure as Code?

5. Why is a shell script of gcloud commands not true IaC?

6. In the Terraform workflow, what should you always do before apply?

Next steps

πŸ—οΈ Terraform vs Pulumi vs OpenTofu

Pick the IaC tool β€” the three-way comparison and the OpenTofu licence story.

☁️ AWS services

The AWS field guide β€” the same tour across Amazon's cloud.

☸️ Cloud native

Containers & Kubernetes β€” the architecture GKE and Cloud Run serve.

🐘 Postgres performance

Tune Cloud SQL β€” read the plan, add the right indexes.

πŸ““ All tutorials

The hub β€” LLMs, agents, data & infra.