This repository provisions infrastructure on Google Cloud Platform (GCP) using Terraform. It sets up a Virtual Private Cloud (VPC) and a Google Kubernetes Engine (GKE) cluster with modular, parameterized support and CI/CD automation via Jenkins.
- Modular design with
vpcandgkeTerraform modules - Supports multiple backend types:
remote,gcs,s3,azurerm - Jenkinsfile for automated provisioning and destruction
- Quick setup for repeatable infrastructure deployments on GCP
-
Clone the repository
-
Change into the project directory
-
Initialize Terraform with a backend config
terraform init -backend-config=<path-to-backend-config-file> -
Preview infrastructure changes
terraform plan -var-file=<path-to-var-file> -
Apply the configuration
terraform apply -var-file=<path-to-var-file>
This project includes a Jenkinsfile with parameterized deployment options:
- Select backend type: remote, gcs, s3, azurerm
- Choose execution mode: local or remote (Terraform Cloud)
- Input backend config and variable files
- Toggle destroy mode for cleanup
- Create a new Jenkins pipeline job
- Point it to this GitHub repository
- Configure the following parameters:
- BACKEND_TYPE (e.g., gcs)
- HCP_EXEC_MODE (e.g., local)
- BACKEND_CONFIG (e.g., gcs-staging.hcl)
- TF_VAR_FILE (e.g., gcp.tfvars)
- DESTROY_TERRAFORM (true/false)
- Trigger the pipeline to deploy or destroy GCP infrastructure
-
Create an environment variable in your Terraform Cloud workspace:
-
Name:
GOOGLE_CREDENTIALS -
Value: Paste your entire GCP JSON key file without newline characters.
To remove newlines from your JSON file, run:
cat CREDENTIALS.json | tr -s '\n' ' ' -
Mark the variable as Sensitive
-
-
Save the variable.
-
All runs in this workspace will use the
GOOGLE_CREDENTIALSenvironment variable to authenticate with Google Cloud Platform.
-
Install GKE Auth Plugin:
-
Ubuntu/Debian:
sudo apt-get install google-cloud-sdk-gke-gcloud-auth-plugin -y
-
RHEL/CentOS/Amazon Linux:
sudo yum install google-cloud-sdk-gke-gcloud-auth-plugin -y
-
-
Configure
kubectl:-
Get the command from the
configure_kubeconfigoutputterraform output -raw configure_kubeconfig
-
Or run the following by replacing with your actual values:
gcloud container clusters get-credentials <CLUSTER_NAME> \ --zone <ZONE> \ --project <PROJECT_ID>
-
