Building data infrastructure on Google Cloud
Terraform · 14 questions
Short notes
Key idea
A small data platform on Google Cloud is a handful of resources: buckets for raw files, BigQuery datasets and tables, a service account with narrow roles, and maybe Pub/Sub and a scheduler. Terraform builds the whole set the same way every time.
Syntax
resource "google_service_account" "etl" {
account_id = "etl-runner"
}
resource "google_bigquery_dataset_iam_member" "etl_writes" {
dataset_id = google_bigquery_dataset.sales.dataset_id
role = "roles/bigquery.dataEditor"
member = "serviceAccount:${google_service_account.etl.email}"
}
resource "google_project_service" "bq" {
service = "bigquery.googleapis.com"
}
Example
One config creates raw and curated buckets with lifecycle rules, a sales dataset with a partitioned orders table, an orders Pub/Sub topic, and an etl-runner service account that can write only to sales.
Traps
- APIs must be enabled (
google_project_service) before resources that use them. _iam_policyresources overwrite all bindings; use_iam_memberto add one.- Changing a table's partitioning forces replacement, which drops the data. Read the plan.
- Set
deletion_protectionon BigQuery tables you care about.
Want the full lesson with step-by-step examples, a project and a certificate? Terraform course, ₹120 →
- Question 1medium
What's the recommended way to let Terraform on your laptop act on Google Cloud?
- Question 2medium
Why set
disable_on_destroy = falseongoogle_project_service? - Question 3easy
What does
force_destroy = falsedo on a bucket? - Question 4medium
Which nested block moves files to a colder storage class after 30 days?
- Question 5hard
Your team builds 200 derived tables with dbt. What should Terraform manage?
Building data infrastructure on Google Cloud
Building data infrastructure on Google Cloud
Building data infrastructure on Google Cloud
Building data infrastructure on Google Cloud
Building data infrastructure on Google Cloud
9 more questions on this topic, with hints, and tests
Sign up free for 21 days of every question and test.