This project demonstrates how to use Terraform and GitHub Actions to provision infrastructure on Google Cloud Platform (GCP).
It creates a Compute Engine Virtual Machine (VM) and a firewall rule to allow incoming traffic.
- Provisioned a GCP VM instance using Terraform.
- Configured a firewall rule to allow external access (e.g., SSH/HTTP).
- Managed infrastructure lifecycle using Infrastructure as Code (IaC).
- Automated Terraform workflows using GitHub Actions CI/CD.
- Stored Terraform state in a remote GCS backend for collaboration.
- Terraform (Infrastructure as Code)
- GCP (Compute Engine, VPC Networking, Firewall Rules)
- GCS (for remote backend state storage)
- GitHub Actions (CI/CD for Terraform)
-
Provider Setup
- Configures GCP provider with project, region, and zone.
-
VM Creation
- Creates a Compute Engine instance with a Debian image.
-
Firewall Rule
- Opens port
22(SSH) and80(HTTP).
- Opens port
-
State Management
- Stores Terraform state in GCS.
-
CI/CD (GitHub Actions)
- Every
pushorpull requesttriggers:terraform fmt(format check)terraform init(initialize backend)terraform plan(dry run)terraform apply(only onmainbranch with approval)
- Every
In your GitHub repo, go to Settings β Secrets and variables β Actions and add:
GCP_CREDENTIALSβ Contents of your GCP Service Account JSON key.GCP_PROJECT_IDβ Your GCP project ID.GCP_REGIONβ (e.g.,us-central1)GCP_ZONEβ (e.g.,us-central1-a)
.github/workflows/terraform.yml:
Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
Outputs:
vm_external_ip = "34.123.45.67"