GCP Scenarios

This guide provides practical deployment scenarios for Google Cloud Platform using Terraform, incorporating modern best practices and patterns for 2025.

GKE Autopilot Cluster

Deploy a production-ready GKE Autopilot cluster with all recommended security features:

module "gke_autopilot" {
  source = "./modules/gke-autopilot"

  project_id = var.project_id
  name       = "prod-cluster"
  region     = "europe-west4"
  
  network_config = {
    network_name    = module.vpc.network_name
    subnet_name     = module.vpc.subnet_names["gke"]
    master_ipv4_cidr_block = "172.16.0.0/28"
    enable_private_nodes   = true
    enable_private_endpoint = true
  }

  security_config = {
    enable_workload_identity  = true
    enable_binary_authorization = true
    enable_network_policy    = true
    enable_shielded_nodes   = true
  }

  maintenance_config = {
    maintenance_start_time = "02:00"
    maintenance_end_time   = "06:00"
    maintenance_recurrence = "FREQ=WEEKLY;BYDAY=SA,SU"
  }

  monitoring_config = {
    enable_managed_prometheus = true
    enable_system_metrics    = true
    enable_workload_metrics = true
  }

  addons_config = {
    http_load_balancing        = true
    horizontal_pod_autoscaling = true
    network_policy_config      = true
    gcp_filestore_csi_driver  = true
  }

  labels = merge(local.common_labels, {
    environment = "production"
    cluster_type = "autopilot"
  })
}

# Cloud SQL for applications
module "cloud_sql" {
  source = "./modules/cloud-sql"

  name           = "prod-db"
  database_version = "POSTGRES_14"
  region         = var.region

  settings = {
    tier              = "db-custom-8-32768"
    availability_type = "REGIONAL"
    
    backup_configuration = {
      enabled                        = true
      start_time                    = "02:00"
      point_in_time_recovery_enabled = true
      retention_period              = "7"
    }
    
    maintenance_window = {
      day          = 7
      hour         = 2
      update_track = "stable"
    }
    
    ip_configuration = {
      ipv4_enabled        = false
      private_network     = module.vpc.network_self_link
      require_ssl         = true
      allocated_ip_range  = module.vpc.psa_ranges["sql"].range_name
    }
  }

  deletion_protection = true
  
  database_flags = [
    {
      name  = "cloudsql.logical_decoding"
      value = "on"
    },
    {
      name  = "log_min_duration_statement"
      value = "1000"
    }
  ]
}

Cloud Run with Cloud Build Pipeline

Deploy a serverless application with automated CI/CD:

VPC with Shared VPC Setup

Create a secure networking setup with Shared VPC:

Cloud Storage with Lifecycle Management

Set up Cloud Storage buckets with intelligent lifecycle management:

Pub/Sub with Cloud Functions

Create an event-driven architecture:

Load Balancer with Cloud CDN

Deploy a global load balancer with CDN:

Best Practices for GCP

1. Resource Organization

2. IAM Best Practices

3. Monitoring and Logging

Last updated