This repository contains Terraform code to provision a Google Kubernetes Engine (GKE) cluster and supporting infrastructure on Google Cloud Platform (GCP).
- Custom VPC and subnets (public/private)
- GKE cluster with node pools
- NAT gateway for private subnet egress
- IAM service accounts and roles for GKE nodes
- Firewall rules for secure access
- Google Cloud APIs enablement
.
├── apis.tf # Enable required GCP APIs
├── firewalls.tf # Firewall rules
├── gke.tf # GKE cluster definition
├── gke-nodes.tf # Node pool and IAM for GKE nodes
├── local.tf # Locals and variables
├── nat.tf # NAT gateway configuration
├── provider.tf # Provider and backend config
├── subnets.tf # Subnet definitions
├── vpc.tf # VPC network definition
- Terraform
- Google Cloud SDK
- A GCP project with billing enabled
- Service account credentials with sufficient permissions
-
Clone the repository:
git clone <repo-url> cd <repo-directory>
-
Initialize Terraform:
terraform init
-
Review and apply the plan:
terraform plan terraform apply
-
Destroy resources (when finished):
terraform destroy
- Edit
local.tfto set your project ID, region, and other variables. - Modify
gke.tfandgke-nodes.tfto adjust cluster/node pool settings. - Update
firewalls.tfto change network access rules.
- State files (
terraform.tfstate*) should not be committed to version control. - The GKE cluster is created without deletion protection. Use the
lifecycleblock if you want to prevent accidental deletion. - Make sure to clean up resources to avoid unnecessary charges.