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.
Foundations The GCP resource hierarchy
Before services, learn how GCP organises them β it drives billing, IAM and blast radius. Everything lives in a tree:
| Level | What it is |
|---|---|
| Organization | Root node tied to your domain β company-wide policies live here. |
| Folder | Optional grouping (by department, team, or environment). |
| Project | The core unit β every resource belongs to exactly one project; it's the boundary for billing, quota, IAM & APIs. |
| Resources | The actual services (a VM, a bucket, a database) inside a project. |
Two more concepts you'll meet constantly:
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.
IAM
Grant roles (bundles of permissions) to principals (users, groups, service accounts) on a resource. Service accounts are the identity your workloads use.
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
| Service | Solves | Reach for it when⦠|
|---|---|---|
| Compute Engine | VMs (IaaS) | You need full control of the OS, GPUs, or a lift-and-shift. |
| Cloud Run | Serverless containers | You have a container and want it to scale to zero with no cluster to manage. The GCP sweet spot. |
| GKE | Managed Kubernetes | You need full Kubernetes β many services, complex networking, portability. See Cloud Native. |
| Cloud Functions | Event-driven functions (FaaS) | Small snippets triggered by an event (a file upload, a Pub/Sub message). |
| App Engine | Managed app platform (PaaS) | You want to push code and let Google run it β the original GCP PaaS. |
ποΈ Storage & databases β keep your data
| Service | Solves | Reach for it when⦠|
|---|---|---|
| Cloud Storage | Object storage | Files, images, backups, static assets, data-lake landing zone (the S3 equivalent). |
| Cloud SQL | Managed Postgres / MySQL / SQL Server | A standard relational DB without running the server yourself. (Pairs with the Postgres performance guide.) |
| AlloyDB | Postgres-compatible, high-performance | You've outgrown Cloud SQL and want Postgres with more throughput/analytics. |
| Spanner | Globally-distributed relational | You need horizontal scale and strong consistency across regions. |
| Firestore | Serverless document NoSQL | Mobile/web apps needing realtime sync and flexible documents. |
| Bigtable | Wide-column NoSQL at massive scale | High-throughput time-series, IoT, or analytics key-value workloads. |
| Memorystore | Managed Redis / Memcached | Caching and low-latency in-memory data. |
π Data & analytics β GCP's crown jewels
| Service | Solves | Reach for it when⦠|
|---|---|---|
| BigQuery | Serverless data warehouse | Analytical SQL over terabytesβpetabytes with no infra. GCP's flagship β often the reason teams pick GCP. |
| Pub/Sub | Global messaging / streaming | Decouple producers & consumers; ingest event streams (SNS+SQS/Kinesis in one). |
| Dataflow | Managed Apache Beam pipelines | Stream or batch ETL that autoscales. |
| Dataproc | Managed Spark / Hadoop | You have existing Spark/Hadoop jobs to run. |
π Networking Β· π€ AI Β· π§ Operations
| Service | Solves |
|---|---|
| VPC | Your private, global software-defined network (subnets, firewall, routing). |
| Cloud Load Balancing | Global anycast L4/L7 load balancing behind one IP. |
| Cloud CDN / Cloud DNS | Edge caching and managed DNS. |
| Vertex AI | End-to-end ML platform: train, tune, deploy, plus the Gemini API. (See Google agent patterns.) |
| Cloud Logging / Monitoring | The observability stack (formerly Stackdriver) β logs, metrics, traces, alerts. |
| Secret Manager | Store & version secrets (API keys, DB passwords) with IAM access. |
| IAM | Who can do what, on which resource β the control plane for everything. |
Translation GCP β AWS quick map
Already know AWS? Map the mental model across. Equivalents are approximate, not identical.
| Category | GCP | AWS |
|---|---|---|
| VMs | Compute Engine | EC2 |
| Serverless containers | Cloud Run | Fargate / App Runner |
| Kubernetes | GKE | EKS |
| Functions (FaaS) | Cloud Functions | Lambda |
| Object storage | Cloud Storage | S3 |
| Managed relational | Cloud SQL | RDS |
| Global relational | Spanner | Aurora (β) / DynamoDB Global |
| Document NoSQL | Firestore | DynamoDB |
| Data warehouse | BigQuery | Redshift / Athena |
| Messaging / streaming | Pub/Sub | SNS + SQS / Kinesis |
| ML platform | Vertex AI | SageMaker / Bedrock |
| Secrets | Secret Manager | Secrets Manager |
| Identity | IAM | IAM |
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
Drift & snowflakes
Consoles create one-off "snowflake" environments no one can reproduce. Staging never quite matches prod.
No review, no audit
A click leaves no diff, no PR, no reviewer. Who opened that firewall port, and when?
Slow & error-prone
Rebuilding an environment by hand takes days and misses steps. Disaster recovery is a prayer.
gcloud commands) lists steps and can't tell what already exists. Declarative is idempotent: run it twice, get the same result.Options IaC tools for GCP
| Tool | What it is | Use when⦠|
|---|---|---|
| Terraform / OpenTofu | Declarative, cloud-agnostic (HCL). The de-facto standard; OpenTofu is the open-source fork. | Almost always β largest ecosystem, multi-cloud, huge module registry. |
| Config Connector | Manage GCP resources as Kubernetes objects (KRM). | You're all-in on GKE and want GitOps via Kubernetes tooling. |
| Pulumi | IaC in real languages (TypeScript, Python, Go). | Your team prefers a general-purpose language and loops/abstractions over HCL. |
| gcloud CLI / scripts | Imperative commands. | Quick experiments & exploration β not durable infrastructure (no state, drifts). |
| Deployment Manager | GCP's native (legacy) IaC. | Rarely for new work β Google steers toward Terraform now. |
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.
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.
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
| Practice | Why |
|---|---|
| Remote state + locking | Store state in a GCS backend, not on a laptop. Locking stops two people applying at once and corrupting it. |
| Plan in CI, apply on approval | Every change is a reviewed PR with a plan attached β no surprise applys. |
| No secrets in code | Reference Secret Manager; never hard-code keys. State can contain secrets β encrypt & lock it down. |
| Modules for reuse | One tested module per pattern; compose environments from it instead of copy-paste. |
| Separate state per environment | Isolate prod from staging so a mistake can't cross the boundary. |
| Least-privilege service account | The CI identity that runs Terraform gets only the roles it needs. See security. |
| Detect drift | Run plan on a schedule; a non-empty diff means someone click-opped β reconcile it. |
Cheat sheet
| Question | Short 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.
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.