terraform-gcp
Skill4 starsChanged 10 months agoMITView on GitHub
Write, review, and refactor Terraform HCL for GCP. Use when editing .tf files, managing IAM, writing terraform tests, or organizing GCP Terraform modules.
3 other projects use a version of this.
Adopted by
Most recently taken up by
- mohitkale/gcp-devkittheir own version, first seen Jul 28, 2026
- jpantsjoha/googlecloud-plugintheir own version, first seen Jul 23, 2026
- eclosion-labs/terraform-cursor-plugintheir own version, first seen Apr 22, 2026
Other versions3 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 3
- jpantsjoha/googlecloud-plugin★ 4same name
- eclosion-labs/terraform-cursor-plugin★ 0same name
- mohitkale/gcp-devkit★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository12 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- aepSkill
- agents-mdSkill
- skill-creatorSkill
- beam-dataflow-pythonSkill
- ileapSkill
- spacelift-terraformSkill
- way-brand-identitySkill
- way-go-styleSkill
- way-magefileSkill
- way-typescript-react-styleSkill
The file
We split this skill into the rules it gives an agent
12 rules. About 0 are common, 3 are distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 47
Use main when there is only one of a type
- Very specific: line 63
Every variable needs type + description.
- Very specific: line 94
Every output needs description.
- Very specific: line 118
Use a separate enable_x boolean for conditional logic.
- Very specific: line 167
Use depends_on only as a last resort.
- Very specific: line 204
Add lifecycle { prevent_destroy = true } to databases, buckets, and other stateful resources:
- Very specific: line 283
Never commit: .terraform/, *.tfstate, *.tfstate.backup, *.tfplan
- Distinctive: line 291
Every resource defined in the module must have at least one output
- Very specific: line 295
Use moved blocks when refactoring to prevent destroy/recreate
- Distinctive: line 323
Use a dedicated test project isolated from dev/prod
- Very specific: line 324
Always destroy after tests: terraform destroy or project_cleanup module
- Very specific: line 325
Run independent tests in parallel: test { parallel = true }
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 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
File Organization
Per references/terraform-style-guide.md (HashiCorp):
| File | Purpose |
terraform.tf | Terraform and provider version requirements |
providers.tf | Provider configurations |
main.tf | Primary resources and data sources |
variables.tf | Input variable declarations (alphabetical) |
outputs.tf | Output value declarations (alphabetical) |
locals.tf | Local value declarations |
For larger modules, split main.tf into purpose-grouped files (references/general-style-and-structure.md, Google):
# dns.tf — google_dns_managed_zone + google_dns_record_set together
# network.tf — VPC, subnets, firewall rules togetherFormatting
- 2 spaces per nesting level, no tabs — always run
terraform fmt -recursive - Align
=for consecutive arguments in the same block - Block order within a resource:
- Meta-arguments (
count,for_each,provider,depends_on) - Arguments
- Nested blocks
lifecyclelast
- Meta-arguments (
Naming Conventions
lowercase_underscoresfor all resource/variable/output names- Descriptive nouns — no resource type in the name
- Singular, not plural
- Use
mainwhen there is only one of a type
# Bad
resource "google_compute_global_address" "main_global_address" {}
resource "google_storage_bucket" "buckets" {}
# Good
resource "google_compute_global_address" "main" {}
resource "google_storage_bucket" "artifacts" {}Variables
Every variable needs type + description. Add validation for constrained inputs.
Mark sensitive = true for secrets. Don't provide defaults for environment-specific
values like project_id — force the caller to provide them.
GCP-specific naming:
- Numeric values: include units —
ram_size_gb,disk_size_gib - Storage: binary prefixes (
kibi,mebi,gibi); all other measurements: decimal - Booleans: positive names —
enable_external_access, notdisable_internal
variable "ram_size_gb" {
description = "RAM per instance in gibibytes"
type = number
}
variable "environment" {
description = "Deployment environment"
type = string
validation {
condition = contains(["dev", "qa", "prod"], var.environment)
error_message = "Must be dev, qa, or prod."
}
}Outputs
Every output needs description. Mark sensitive = true where appropriate.
Never pass an input variable directly as an output — always reference a resource attribute to preserve the dependency graph:
# Bad — breaks implicit dependencies
output "bucket_name" {
value = var.bucket_name
}
# Good — reference the resource attribute
output "bucket_name" {
description = "Name of the storage bucket"
value = google_storage_bucket.main.name
}for_each vs count
for_each— multiple named resources (stable identity, survives reordering)count— conditional creation only- Use a separate
enable_xboolean for conditional logic; don't drivecountdirectly from resource attributes that may be unknown at plan time
# Multiple resources — use for_each
resource "google_storage_bucket" "regional" {
for_each = toset(var.regions)
name = "data-${each.key}"
location = each.key
}
# Conditional — use count
resource "google_monitoring_alert_policy" "latency" {
count = var.enable_alerts ? 1 : 0
display_name = "High Latency Alert"
}Dependency Management (CRITICAL)
Prefer implicit over explicit. Reference output attributes — not input args — to create real ordering. Input args are known at plan time and create no dependency; output attrs are only known after creation.
# Bad — .name is an input arg, Terraform sees no dependency
bucket = google_storage_bucket.main.name
# Good — .id is an output attr, creates real implicit dependency
bucket = google_storage_bucket.main.idModule dependency — implicit via output reference:
# Bad — depends_on is a blunt instrument, slows planning
module "bigquery" {
project_id = var.project_id
depends_on = [module.project_services]
}
# Good — implicit dependency, Terraform tracks exactly what changed
module "bigquery" {
project_id = module.project_services.project_id
}Use depends_on only as a last resort. Always add a comment explaining why.
Cross-config dependencies: use terraform_remote_state (GCS backend). Don't use
data sources to reference resources managed by another Terraform config.
IAM — Authoritative vs Additive (CRITICAL)
| Resource pattern | Behavior | Use? |
google_*_iam_policy | Authoritative — overwrites ALL roles, removes Google-managed accounts | AVOID |
google_*_iam_binding | Authoritative — overwrites that specific role's bindings | Avoid unless owning the entire role |
google_*_iam_member | Additive — adds one member, leaves all others untouched | PREFERRED |
Authoritative resources silently remove Google's auto-managed service account roles,
breaking Cloud services. Default to google_*_iam_member.
# Bad — removes all other IAM, including Google-managed bindings
resource "google_project_iam_policy" "main" {
project = var.project_id
policy_data = data.google_iam_policy.admin.policy_data
}
# Good — additive, safe
resource "google_project_iam_member" "invoker" {
project = var.project_id
role = "roles/run.invoker"
member = "serviceAccount:${google_service_account.worker.email}"
}Stateful Resource Protection
Add lifecycle { prevent_destroy = true } to databases, buckets, and other
stateful resources:
resource "google_sql_database_instance" "main" {
name = "primary"
database_version = "POSTGRES_15"
lifecycle {
prevent_destroy = true
}
}Compute / VM
- Bake images with Packer — do NOT use provisioners for configuration
- Pass runtime config via instance metadata, not provisioner scripts
Version Pinning
Root modules — pin to minor, allow patch updates:
terraform {
required_version = ">= 1.7"
required_providers {
google = {
source = "hashicorp/google"
version = "~> 6.0.0"
}
}
}Reusable modules — permissive >=, let callers decide:
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 4.0.0"
}
}
}Root Module Structure
service/
├── OWNERS
├── modules/
│ └── <service-name>/
│ ├── main.tf
│ ├── variables.tf
│ ├── outputs.tf
│ └── README.md
└── environments/
├── dev/
│ ├── backend.tf # GCS backend
│ ├── main.tf # Instantiates service module
│ └── terraform.tfvars
├── qa/
└── prod/- Max ~100 resources per state (ideally a few dozen) — per
references/root-modules.md(Google) - One directory per application/service; nest all code under it
- Default workspace only — no multiple CLI workspaces
- Variables in
terraform.tfvars; check in.terraform.lock.hcl - Never commit:
.terraform/,*.tfstate,*.tfstate.backup,*.tfplan
Reusable Module Rules
- No
providerorbackendconfig — root modules own these - Expose
labels = {}variable for every module - Every resource defined in the module must have at least one output
- Enable APIs via
google_project_service; exposeenable_apis = truevariable; always setdisable_services_on_destroy = false - Inline submodules in
modules/<name>/ - Use
movedblocks when refactoring to prevent destroy/recreate - Release with SemVer; callers reference with
~> major.0
Testing
Two categories of .tftest.hcl tests:
| Type | Naming | Mode | Creates resources? |
| Unit | *_unit_test.tftest.hcl | plan | No — fast, safe |
| Integration | *_integration_test.tftest.hcl | apply | Yes — real infra |
run "bucket_name_follows_convention" {
command = plan
assert {
condition = google_storage_bucket.main.name == "myproject-artifacts"
error_message = "Bucket name does not match expected pattern."
}
}Key practices:
- Randomize resource names/project IDs to avoid collisions
- Use a dedicated test project isolated from dev/prod
- Always destroy after tests:
terraform destroyorproject_cleanupmodule - Run independent tests in parallel:
test { parallel = true } - Order:
terraform validate→ unit tests → integration tests → e2e
See references/terraform-test.md for full .tftest.hcl syntax, mock
providers, expect_failures, and parallel execution rules.
Import / Export
Export existing GCP resources:
gcloud beta resource-config bulk-export \
--project=MY_PROJECT \
--resource-format=terraform \
--path=./exported/Import one resource:
terraform import google_storage_bucket.main my-project/my-bucketBulk import with generated config (Terraform 1.5+):
import {
id = "projects/MY_PROJECT/global/networks/my-network"
to = google_compute_network.main
}terraform plan -generate-config-out=generated.tfSee references/import-google-cloud-resources.md and
references/export-google-cloud-resources.md for full workflows.
Reference Files
| File | Read when |
references/terraform-style-guide.md | Full HashiCorp style guide: formatting, block order, naming, security patterns |
references/terraform-test.md | Complete .tftest.hcl syntax: run/assert/mock blocks, parallel execution, expect_failures |
references/general-style-and-structure.md | Module structure, data source placement, static files, helper scripts, expression complexity |
references/root-modules.md | Root module patterns, remote state, environment dirs, workspace rules |
references/reusable-modules.md | API activation, OWNERS file, SemVer releases, submodule patterns, moved blocks |
references/dependency-management.md | Implicit vs explicit deps with full examples, cross-config remote state |
references/working-with-google-cloud-resources.md | IAM authoritative vs additive detail, VM baking |
references/testing.md | GCP testing strategies, parallel execution, test environment isolation, cleanup |
references/import-google-cloud-resources.md | Step-by-step import workflows, import block + generate-config-out |
references/export-google-cloud-resources.md | Bulk export with gcloud beta resource-config, supported resource types |
references/blueprints.md | Cloud Foundation Toolkit blueprint patterns |
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.

