terraform-gcp-scaffolder
Skill0 starsChanged 3 months agoMITView on GitHub
Generate and review Terraform for GCP data platform resources, including BigQuery datasets, Cloud Run jobs, service accounts, IAM, Pub/Sub, Secret Manager, and Composer environments. Use when the user mentions Terraform, IaC, tfstate, provisioning GCP resources, service account permissions, least privilege, or asks to stand up a new environment or project.
- Reads credentials
In this repository10 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- gcp-data-engineeringSkill
- analytics-hub-publisherSkill
- bq-cost-auditorSkill
- bq-schema-contractSkill
- composer-dag-builderSkill
- dataform-modelerSkill
- de-pr-reviewerSkill
- pipeline-incident-triageSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 2 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 8
Read references/conventions.md for naming and labels.
- Distinctive: line 107
Never create service account keys in Terraform.
- Very specific: line 167
Read references/execution-model.md.
- Very specific: line 172
When scaffolding IAM for an agent that will use the BigQuery MCP server, grant roles/mcp.toolUser, roles/bigquery.jobUser, and …
- Very specific: line 179
Every resource carries env, owner, domain labels.
- Distinctive: line 181
No service account keys.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Terraform GCP scaffolder
Read references/conventions.md for naming and labels.
Layout
infra/
modules/
bq-dataset/
cloud-run-job/
service-account/
envs/
dev/ main.tf terraform.tfvars backend.tf
prod/ main.tf terraform.tfvars backend.tfOne state file per environment, remote backend in GCS with versioning on. Never share state between dev and prod, and never let a module create its own project.
# envs/prod/backend.tf
terraform {
required_version = ">= 1.9"
backend "gcs" {
bucket = "acme-tfstate-prod"
prefix = "data-platform"
}
required_providers {
google = {
source = "hashicorp/google"
version = "~> 6.0"
}
}
}BigQuery dataset module
# modules/bq-dataset/main.tf
resource "google_bigquery_dataset" "this" {
dataset_id = var.dataset_id
project = var.project_id
location = var.location
description = var.description
delete_contents_on_destroy = false
default_partition_expiration_ms = var.partition_expiration_days == null ? null : var.partition_expiration_days * 86400000
labels = merge(var.labels, {
env = var.env
domain = var.domain
owner = var.owner
})
}
resource "google_bigquery_dataset_iam_member" "readers" {
for_each = toset(var.reader_members)
project = var.project_id
dataset_id = google_bigquery_dataset.this.dataset_id
role = "roles/bigquery.dataViewer"
member = each.value
}
resource "google_bigquery_dataset_iam_member" "writers" {
for_each = toset(var.writer_members)
project = var.project_id
dataset_id = google_bigquery_dataset.this.dataset_id
role = "roles/bigquery.dataEditor"
member = each.value
}Grant at the dataset level, not the project level. roles/bigquery.dataViewer
on a project is how an intern reads payroll.
Service account with least privilege
resource "google_service_account" "dataform" {
account_id = "sa-dataform-${var.env}"
display_name = "Dataform execution, ${var.env}"
project = var.project_id
}
# Job runner at project level, data access scoped per dataset
resource "google_project_iam_member" "dataform_job_user" {
project = var.project_id
role = "roles/bigquery.jobUser"
member = "serviceAccount:${google_service_account.dataform.email}"
}
resource "google_bigquery_dataset_iam_member" "dataform_writes_marts" {
project = var.project_id
dataset_id = "mart_retail"
role = "roles/bigquery.dataEditor"
member = "serviceAccount:${google_service_account.dataform.email}"
}Never create service account keys in Terraform. Use workload identity federation for CI and the attached service account for Cloud Run and Composer. If someone asks for a key file, ask what they are authenticating from first, because the answer is almost always something that supports WIF.
Cloud Run job on a schedule
resource "google_cloud_run_v2_job" "loader" {
name = "job-${var.name}-${var.env}"
location = var.region
project = var.project_id
template {
task_count = 1
template {
service_account = google_service_account.job.email
max_retries = 3
timeout = "1800s"
containers {
image = var.image
resources {
limits = { cpu = "1", memory = "2Gi" }
}
dynamic "env" {
for_each = var.secrets
content {
name = env.key
value_source {
secret_key_ref {
secret = env.value
version = "latest"
}
}
}
}
}
}
}
}
resource "google_cloud_scheduler_job" "trigger" {
name = "sched-${var.name}-${var.env}"
schedule = var.cron
time_zone = "UTC"
project = var.project_id
region = var.region
http_target {
http_method = "POST"
uri = "https://${var.region}-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/${var.project_id}/jobs/${google_cloud_run_v2_job.loader.name}:run"
oauth_token {
service_account_email = google_service_account.scheduler.email
}
}
}Plan is a read, apply is not
Read references/execution-model.md. Run terraform plan and read the output,
specifically the destroy list, because a plan that quietly re-creates a stateful
resource is the finding that matters. Never run terraform apply, and never run
terraform state subcommands that mutate state.
When scaffolding IAM for an agent that will use the BigQuery MCP server, grant
roles/mcp.toolUser, roles/bigquery.jobUser, and roles/bigquery.dataViewer
to a dedicated service account, never to a human's identity, and pair it with a
deny policy on read-write MCP tool use.
Review checklist
- Every resource carries
env,owner,domainlabels. - No
roles/editor, noroles/owner, noallUsers, no primitive roles at all. - No service account keys.
prevent_destroyon state buckets, production datasets, and Composer.- Variables have types and descriptions.
variable "x" {}with no type is a bug. for_eachovercountfor anything keyed by name, so adding one entry does not re-create the others.- Provider version pinned with
~>, not floating.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

