06 — GCP Project & APIs
← Previous: 05 — Project Setup & Terraform State
Before Terraform can create resources, we need a GCP project and must enable the APIs that Terraform will manage.
Create a GCP project
If you don't have a GCP project yet, create one:
# Create a new project
gcloud projects create mycoolproject-prod --name="My Cool Project"
# Set it as your active project
gcloud config set project mycoolproject-prod
If you already have a project, skip to setting the active project:
Get your project ID (you'll need it for Terraform):
Enable GCP APIs
Terraform manages these GCP services, so we need to enable their APIs:
# Enable APIs needed for this guide
gcloud services enable \
run.googleapis.com \
cloudbuild.googleapis.com \
artifactregistry.googleapis.com \
cloudscheduler.googleapis.com \
tasks.googleapis.com \
storage.googleapis.com \
secretmanager.googleapis.com \
vpcaccess.googleapis.com \
servicenetworking.googleapis.com \
compute.googleapis.com
These APIs power Cloud Run, Cloud Storage, Secret Manager, Serverless VPC, and more.
Project ID vs Project Number
- Project ID — your unique identifier (e.g.,
mycoolproject-prod) - Project Number — a numeric identifier (e.g.,
123456789012)
Terraform uses both:
- project in provider config = project ID
- Some resources need project number for IAM bindings
Get your project number:
Add both to infrastructure/terraform.tfvars:
Terraform: Enable APIs via resource
Alternatively, you can let Terraform enable APIs automatically using the google-project-service-enforcement resource. Add to main.tf:
# Enable required APIs
resource "google_project_service" "apis" {
for_each = toset([
"run.googleapis.com",
"cloudbuild.googleapis.com",
"artifactregistry.googleapis.com",
"cloudscheduler.googleapis.com",
"tasks.googleapis.com",
"storage.googleapis.com",
"secretmanager.googleapis.com",
"vpcaccess.googleapis.com",
"servicenetworking.googleapis.com",
"compute.googleapis.com",
])
project = var.project_id
service = each.value
disable_dependent_services = false
disable_on_destroy = false
}
This approach makes API enablement part of your Terraform state — useful for reproducibility.
Navigation
- 01 — Introduction: What We're Building
- 02 — Terraform Overview
- 03 — Cloud Services Explained
- 04 — PlanetScale Database Explained
- 05 — Project Setup & Terraform State
- 06 — GCP Project & APIs (Current chapter)
- 07 — Artifact Registry
- 08 — Secrets Management
- 09 — Cloud Storage
- 10 — Service Accounts & IAM
- 11 — Cloud Run
- 12 — Cloud Tasks & Scheduler
- 13 — Dockerfile
- 14 — First Deploy
- 15 — Custom Domain & SSL
- 16 — Workload Identity Federation
- 17 — GitHub Actions CI/CD
- 18 — Quick Reference