Lesson 11 · Identity, secrets & operations
Networking, DNS & Cloud SQL
The private network the cluster lives in, the DNS/certs that let traffic in, and the databases behind your services.
Your win: read the VPC, Cloudflare, and Cloud SQL modules — the network the GKE cluster runs inside, the DNS + edge certs behind Istio's gateway (C4), and the Postgres instances your services talk to.
VPC — the private network everything sits in
terraform-google-modules/network and provisions: subnets +
secondary ranges (Pod/Service IP ranges, :1-12),
private service access peering so the cluster can reach Cloud SQL privately
(:14-27), Cloud NAT with static egress IPs
(:67-110), and VPC access connectors. Remember Lesson 8's
private_network = dependency.vpc.outputs.network_self_link? This module produces
that output — the VPC is created before the cluster that depends on it (the module
dependency graph, Lesson 4).
Cloudflare — DNS & the edge certs (Course 4)
cloudflare_record (records.tf:6, all the DNS records
like api.*, thanos) and cloudflare_certificate_pack
(certificate_pack.tf:1-15, the edge certs for proxied hosts). So
"how does api.prod.tokyo.manabie.io resolve, and where does its edge cert come
from?" → this module. (Interesting: thanos's DNS record is here even though its
bucket isn't Terraform-managed — the map isn't always the whole territory.)
Cloud SQL — the databases behind your services
for_each over var.postgresql,
:1-8, wrapping GoogleCloudPlatform/sql-db); the stag
instance list has five: lms, common, auth, lmsdwh, aitutor — mostly
POSTGRES_14, with IAM auth, pgaudit, pg_cron, deletion_protection,
ssl_mode: ENCRYPTED_ONLY, and a private network from the VPC dependency. The
separate modules/postgresql (singular) then manages the
databases/users/roles inside those instances (via a data source — Lesson 2). So
"instance" and "the DBs in it" are two modules — one creates the server, one configures its
contents.
GCP — VPC, Cloud SQL for PostgreSQL (+ the Cloudflare provider)
Private networking, managed Postgres, and DNS-as-code.
→ cloud.google.com — VPC ·
Cloud SQL for PostgreSQL
→ registry — cloudflare provider
Check yourself (from memory)
Q1. The GKE cluster reaches Cloud SQL privately thanks to…
private_network — no public DB exposure.
Q2. Istio's edge certs and the DNS records come from…
cloudflare_record + cloudflare_certificate_pack
— the DNS + edge certs behind Course 4's gateway.
Q3. Creating a Cloud SQL instance vs the databases in it is…
platforms/postgresql.tf creates the instance;
modules/postgresql manages DBs/users inside it (via a data source).
modules/vpc, wraps terraform-google-modules/network):
subnets + secondary ranges, PRIVATE SERVICE ACCESS peering (so the cluster reaches Cloud SQL
privately), Cloud NAT + static egress IPs, VPC connectors — produces the
network_self_link the GKE cluster depends on (L8). CLOUDFLARE
(modules/cloudflare-dns): cloudflare_record (DNS) +
cloudflare_certificate_pack (edge certs) — behind Course 4's ingress gateway.
CLOUD SQL: platforms/postgresql.tf creates INSTANCES (lms/common/auth/lmsdwh/
aitutor; POSTGRES_14, IAM auth, ENCRYPTED_ONLY, private network); modules/postgresql
manages DBs/users INSIDE them (data source). CONNECTIVE TISSUE: VPC → Cloud SQL + cluster →
DNS; Terraform's dependency graph builds them in order.1. In-repo: modules/vpc/main.tf, modules/cloudflare-dns/, modules/platforms/postgresql.tf.