Infrastructure as Code on Google Cloud: Terraform, Infrastructure Manager, Config Controller and Cloud Foundation Blueprints
Why Infrastructure as Code?
- Manual clicking is slow, hard to repeat and hard to review
- Code in Git gives review, history, rollback and repeatability
- Same code can build dev, test and prod with different variables
- Google recommends Terraform as the primary IaC tool. Deployment Manager is being phased out, so plan to move off it
Terraform Basics
| Concept | Meaning |
|---|---|
| Provider | Plugin that talks to an API (hashicorp/google) |
| Resource | A thing to create (a bucket, a VM) |
| Variable / Output | Inputs and results |
| State | Terraform's record of what exists. Keep it in a remote backend (Cloud Storage bucket with versioning) |
| Module | Reusable package of resources |
| Plan / Apply | Preview changes, then make them |
hcl
terraform {
required_providers { google = { source = "hashicorp/google", version = "~> 6.0" } }
backend "gcs" { bucket = "acme-tf-state" prefix = "shop/prod" }
}
provider "google" { project = var.project_id region = var.region }
variable "project_id" { type = string }
variable "region" { type = string default = "asia-south1" }
resource "google_storage_bucket" "reports" {
name = "${var.project_id}-reports"
location = var.region
uniform_bucket_level_access = true
public_access_prevention = "enforced"
versioning { enabled = true }
}
resource "google_service_account" "app" { account_id = "report-app" }
resource "google_storage_bucket_iam_member" "app_read" {
bucket = google_storage_bucket.reports.name
role = "roles/storage.objectViewer"
member = "serviceAccount:${google_service_account.app.email}"
}
output "bucket_url" { value = google_storage_bucket.reports.url }
bash
terraform init
terraform fmt && terraform validate
terraform plan -var="project_id=my-proj" -out=tfplan
terraform apply tfplan
terraform destroy -var="project_id=my-proj"
Good Terraform Practices
- Use a remote state bucket with versioning and tight IAM. Never commit state files
- Never put secrets in code or state. Reference Secret Manager
- Use modules and a layout such as
modules/,envs/dev,envs/prod - Pin provider versions
- Run
planin pull requests and require review beforeapply - Use service account impersonation or Workload Identity Federation in pipelines, not key files
- Tag resources with labels
Google's Managed Options
| Tool | What it is |
|---|---|
| Infrastructure Manager | Google-managed service that runs Terraform for you with deployments, revisions and previews |
| Config Connector | Create Google Cloud resources with Kubernetes YAML (declarative, for GitOps teams) |
| Cloud Foundation Toolkit / Terraform blueprints | Ready, tested modules for landing zones, networks, projects and security |
| Service Catalog / Application Design Center | Approved templates for developers |
| Cloud Build / GitHub Actions | Pipelines that run plan and apply |
Landing Zone as Code
- Define organization policies, folders, projects, Shared VPC, logging sinks and IAM in Terraform
- Separate foundation (rarely changes, strict approval) from application stacks (teams change often)
- Use drift detection: run
terraform planon a schedule to find manual changes
A Simple Pipeline
text
Pull request ─► fmt + validate + security scan (Checkov / tfsec) ─► terraform plan (posted as comment)
Merge to main ─► approval ─► terraform apply in Cloud Build ─► outputs and notifications
Practice
- Create the sample bucket and service account with Terraform
- Move the state to a Cloud Storage backend
- Wrap the bucket in a module and use it twice
- Run
terraform planafter changing a label by hand and see the drift
Conclusion
Use Terraform (or Infrastructure Manager) to describe Google Cloud in code. Keep remote state, use modules, review plans in pull requests, authenticate with impersonation, and build landing zones from blueprints.
Quick Summary: why; Terraform; example; practices; managed options; landing zone; pipeline.

