A comprehensive collection of production-ready Terraform modules for Google Cloud Platform (GCP) infrastructure management. This repository provides enterprise-grade modules for container orchestration, networking, project management, and service account administration.
Enterprise-ready GKE cluster creation and management.
Key Features:
- Private cluster configuration with custom networking
- Workload Identity integration for secure service access
- Network policies and security hardening
- Master authorized networks and private endpoints
- Maintenance windows and upgrade management
- Comprehensive add-ons configuration (Istio, Ingress, etc.)
- Multi-zone and regional cluster support
- Shielded nodes with secure boot
Flexible and scalable GKE node pool management.
Key Features:
- Dynamic autoscaling with custom metrics
- Multiple machine types and disk configurations
- Spot and preemptible instances for cost optimization
- GPU support for ML/AI workloads
- Advanced taints, labels, and scheduling
- Security configurations and custom service accounts
- Local SSD and persistent disk options
Comprehensive VPC networking infrastructure management.
Key Features:
- VPC Management: Custom VPC networks with flexible routing
- Subnet Configuration: Primary and secondary IP ranges for GKE
- Custom Routes: Advanced routing rules and traffic flow control
- Firewall Rules: Comprehensive security rule management
- Cloud NAT: Managed NAT gateway for private subnets
- Network Peering: VPC-to-VPC connectivity
- Shared VPC: Enterprise multi-project networking
- Private Service Connect: Secure Google services access
- Flow Logs: Network traffic monitoring and analysis
Sub-modules:
vpc/- VPC network creation and managementsubnets/- Subnet configuration with secondary rangesroutes/- Custom routing managementfirewall-rules/- Security rules and Cloud Armor policies
Enterprise-grade project creation and management at scale.
Key Features:
- Project Lifecycle: Automated project creation with governance
- IAM Management: Comprehensive role and service account management
- Budget Controls: Automated budget setup with multi-threshold alerts
- Service Management: API enablement and configuration
- Organization Policies: Compliance and security guardrails
- Shared VPC Integration: Service project attachment
- Multi-Environment: Standardized dev/staging/prod setups
- Cost Attribution: Proper labeling and cost tracking
Sub-modules:
project/- Core project creation and configurationservices/- API and service managementiam/- Identity and access managementbudget/- Billing and cost management
Advanced service account management with enterprise features.
Key Features:
- Service account creation with custom naming conventions
- Project and cross-project IAM role assignments
- Service account key generation with rotation policies
- Custom IAM role creation and management
- Workload Identity integration for GKE workloads
- Service account impersonation chains
- API enablement and quota management
# Create service accounts
module "service_accounts" {
source = "./service-account"
project_id = "my-gcp-project"
service_accounts = {
"gke-workload" = {
display_name = "GKE Workload Service Account"
roles = [
"roles/storage.objectViewer",
"roles/monitoring.metricWriter"
]
workload_identity_users = ["default/my-app"]
}
}
}
# Create a GKE cluster
module "gke_cluster" {
source = "./container-cluster"
project_id = "my-gcp-project"
cluster_name = "my-cluster"
location = "us-central1"
}
# Create node pools
module "gke_node_pools" {
source = "./container-node-pools"
project_id = "my-gcp-project"
cluster_name = module.gke_cluster.cluster_name
location = "us-central1"
node_pools = {
"default-pool" = {
machine_type = "e2-medium"
autoscaling = {
min_node_count = 1
max_node_count = 3
}
}
}
}tf-gcp-modules/
βββ README.md # This file - comprehensive overview
βββ validate.sh # Module validation script
β
βββ container-cluster/ # π’ GKE cluster module
β βββ main.tf # Main cluster configuration
β βββ variables.tf # Input variables
β βββ outputs.tf # Output values
β βββ provider.tf # Provider requirements
β
βββ container-node-pools/ # π GKE node pools module
β βββ main.tf # Node pool resources
β βββ variables.tf # Input variables
β βββ outputs.tf # Output values
β βββ provider.tf # Provider requirements
β
βββ service-account/ # π Service account module
β βββ main.tf # Service account resources
β βββ variables.tf # Input variables
β βββ outputs.tf # Output values
β βββ provider.tf # Provider requirements
β βββ README.md # Module documentation
β βββ examples/ # Service account examples
β βββ basic/ # Basic service accounts
β βββ with-keys/ # Service accounts with keys
β βββ workload-identity/ # Workload Identity setup
β βββ custom-roles/ # Custom IAM roles
β βββ README.md # Examples documentation
β
βββ compute-network/ # π Networking infrastructure module
β βββ main.tf # Main orchestrator
β βββ variables.tf # Input variables
β βββ outputs.tf # Output values
β βββ provider.tf # Provider requirements
β βββ README.md # Module documentation
β βββ vpc/ # VPC sub-module
β β βββ main.tf
β β βββ variables.tf
β β βββ outputs.tf
β β βββ provider.tf
β β βββ README.md
β βββ subnets/ # Subnets sub-module
β β βββ main.tf
β β βββ variables.tf
β β βββ outputs.tf
β β βββ provider.tf
β βββ routes/ # Routes sub-module
β β βββ main.tf
β β βββ variables.tf
β β βββ outputs.tf
β β βββ provider.tf
β βββ firewall-rules/ # Firewall rules sub-module
β β βββ main.tf
β β βββ variables.tf
β β βββ outputs.tf
β β βββ provider.tf
β βββ examples/ # Networking examples
β βββ basic-network.tf
β βββ gke-network.tf
β βββ shared-vpc.tf
β βββ README.md
β
βββ project-factory/ # ποΈ Project management module
β βββ main.tf # Main orchestrator
β βββ variables.tf # Input variables
β βββ outputs.tf # Output values
β βββ provider.tf # Provider requirements
β βββ README.md # Module documentation
β βββ project/ # Project creation sub-module
β β βββ main.tf
β β βββ variables.tf
β β βββ outputs.tf
β βββ services/ # API/service management sub-module
β β βββ main.tf
β β βββ variables.tf
β βββ iam/ # IAM management sub-module
β β βββ main.tf
β βββ budget/ # Budget management sub-module
β β βββ main.tf
β βββ examples/ # Project factory examples
β βββ basic-project.tf
β βββ multi-environment.tf
β
βββ examples/ # π Global usage examples
βββ main.tf # Complete infrastructure example
βββ variables.tf # Example variables
βββ outputs.tf # Example outputs
βββ terraform.tfvars.example # Sample values
βββ README.md # Examples documentation
# Create projects with project factory
module "projects" {
source = "./project-factory"
billing_account = "ABCDEF-012345-6789AB"
organization_id = "123456789012"
projects = {
"gke-project" = {
project_id = "my-gke-cluster"
services = [
"container.googleapis.com",
"compute.googleapis.com",
"monitoring.googleapis.com"
]
}
}
}
# Create VPC network
module "network" {
source = "./compute-network"
project_id = module.projects.project_ids["gke-project"]
vpcs = {
"gke-vpc" = {
description = "VPC for GKE cluster"
}
}
subnets = {
"gke-subnet" = {
network = "projects/${module.projects.project_ids["gke-project"]}/global/networks/gke-vpc"
ip_cidr_range = "10.0.0.0/20"
region = "us-central1"
secondary_ip_ranges = [
{
range_name = "gke-pods"
ip_cidr_range = "10.4.0.0/14"
},
{
range_name = "gke-services"
ip_cidr_range = "10.0.16.0/20"
}
]
}
}
}
# Create service accounts
module "service_accounts" {
source = "./service-account"
project_id = module.projects.project_ids["gke-project"]
service_accounts = {
"gke-nodes" = {
display_name = "GKE Node Service Account"
roles = [
"roles/monitoring.metricWriter",
"roles/logging.logWriter",
"roles/storage.objectViewer"
]
}
}
}
# Create GKE cluster
module "gke_cluster" {
source = "./container-cluster"
project_id = module.projects.project_ids["gke-project"]
cluster_name = "primary-cluster"
location = "us-central1"
network = module.network.vpc_names["gke-vpc"]
subnetwork = module.network.subnet_names["gke-subnet"]
secondary_range_name_pods = "gke-pods"
secondary_range_name_services = "gke-services"
}
# Create node pools
module "gke_node_pools" {
source = "./container-node-pools"
project_id = module.projects.project_ids["gke-project"]
cluster_name = module.gke_cluster.cluster_name
location = "us-central1"
node_pools = {
"primary-pool" = {
machine_type = "e2-standard-4"
service_account = module.service_accounts.emails["gke-nodes"]
autoscaling = {
min_node_count = 1
max_node_count = 10
}
}
}
}- Private Clusters: No external IP addresses on nodes
- Workload Identity: Secure pod-to-GCP service authentication
- Network Policies: Microsegmentation and traffic control
- Shielded Nodes: Secure boot and integrity monitoring
- Master Authorized Networks: Control plane access restriction
- Organization Policies: Compliance and governance controls
- Service Account Management: Principle of least privilege
- Auto-repair & Auto-upgrade: Self-healing infrastructure
- Multi-zone Deployment: Cross-zone redundancy
- Maintenance Windows: Controlled update scheduling
- Health Monitoring: Comprehensive observability
- Disaster Recovery: Backup and restore capabilities
- Spot Instances: Up to 80% cost savings for fault-tolerant workloads
- Preemptible Nodes: Alternative cost-saving compute option
- Cluster Autoscaling: Dynamic resource allocation
- Budget Controls: Automated budget monitoring and alerts
- Resource Right-sizing: Optimal instance type selection
- GPU Support: NVIDIA Tesla for ML/AI workloads
- Local SSDs: High-performance ephemeral storage
- Custom Taints & Tolerations: Advanced workload scheduling
- Multiple Node Pools: Heterogeneous compute environments
- Shared VPC: Enterprise network architecture
- Terraform:
>= 1.0 - Google Cloud Provider:
>= 4.0 - Google Beta Provider:
>= 4.0(for advanced features)
- Cloud Resource Manager API
- Compute Engine API
- Kubernetes Engine API
- Container Registry API
- Cloud Monitoring API
- Cloud Logging API
- Identity and Access Management (IAM) API
- Service Networking API
- Cloud Billing API
Your service account needs:
roles/container.clusterAdminroles/compute.networkAdminroles/iam.serviceAccountAdminroles/resourcemanager.projectIamAdminroles/billing.projectManager
git clone <repository-url>
cd tf-gcp-modules# Option 1: User credentials
gcloud auth application-default login
# Option 2: Service account key
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/service-account.json"
# Option 3: Workload Identity (when running in GKE)
# No additional setup requiredterraform init# Review the plan
terraform plan -var-file="terraform.tfvars"
# Apply changes
terraform apply -var-file="terraform.tfvars"module "dev_infrastructure" {
source = "./project-factory"
projects = {
"dev-project" = {
project_id = "my-app-dev"
auto_generate_suffix = true
budget = {
amount = { specified_amount = { units = "100" } }
}
labels = {
environment = "development"
team = "engineering"
}
}
}
}module "prod_infrastructure" {
source = "./project-factory"
projects = {
"prod-project" = {
project_id = "my-app-production"
lien = true # Prevent deletion
budget = {
amount = { specified_amount = { units = "5000" } }
threshold_rules = [
{ threshold_percent = 0.5 },
{ threshold_percent = 0.8 },
{ threshold_percent = 1.0 }
]
}
labels = {
environment = "production"
criticality = "high"
}
}
}
}module "global_network" {
source = "./compute-network"
vpcs = {
"global-vpc" = {
routing_mode = "GLOBAL"
description = "Global VPC for multi-region deployment"
}
}
subnets = {
"us-central1-subnet" = {
network = "projects/${var.project_id}/global/networks/global-vpc"
ip_cidr_range = "10.1.0.0/20"
region = "us-central1"
}
"europe-west1-subnet" = {
network = "projects/${var.project_id}/global/networks/global-vpc"
ip_cidr_range = "10.2.0.0/20"
region = "europe-west1"
}
"asia-southeast1-subnet" = {
network = "projects/${var.project_id}/global/networks/global-vpc"
ip_cidr_range = "10.3.0.0/20"
region = "asia-southeast1"
}
}
}- GKE clusters with Istio service mesh
- Private networking with Cloud NAT
- Workload Identity for service authentication
- Multi-environment project setup
- GPU-enabled node pools for ML workloads
- High-memory instances for big data processing
- Spot instances for cost-effective batch jobs
- Integration with Cloud Storage and BigQuery
- Shared VPC for network isolation
- Custom service accounts with minimal permissions
- Organization policies for compliance
- Budget controls and cost attribution
- Separate environments (dev, staging, prod)
- CI/CD integration with Cloud Build
- Automated testing and deployment
- Cost optimization for development workloads
See individual module READMEs for detailed configuration options:
- Container Cluster Configuration
- Node Pools Configuration
- Service Account Management
- Network Infrastructure
- Project Factory Setup
Contributions are welcome! Please see our Contributing Guidelines for details.
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.
For questions and support:
- Check the examples directory
- Review individual module documentation
- Search existing GitHub issues
- Create a new issue for bugs or feature requests