Fully Automated CI/CD Pipeline with Terraform, Jenkins & AW

Static Website CI/CD using Terraform + Jenkins + AWS
DevOps • Terraform • Jenkins • AWS

Static Website CI/CD using Terraform, Jenkins & AWS EC2

In this blog, I explain how I deployed a static website on AWS EC2 and automated the entire process using Terraform, Jenkins, GitHub, NGINX, and Webhooks. The goal was: “Push code to GitHub → Jenkins auto-deploys → Website updates instantly.”

1️⃣ Project Summary

  • Terraform – Creates infrastructure (EC2, Security Groups, SSH keys)
  • AWS EC2 – One Jenkins server, one Static website server
  • NGINX – Hosts static HTML website
  • Jenkins CI/CD – Automates deployment on every GitHub push
  • GitHub Webhook – Triggers pipeline automatically

This project is a perfect starter for learning DevOps + CI/CD automation fundamentals.

2️⃣ High-Level Architecture

The workflow:

GitHub → Jenkins → EC2 Website Server → NGINX → Browser

3️⃣ Why This Architecture Works

  • Terraform makes infra reproducible
  • NGINX is fast & lightweight for static hosting
  • Jenkins handles CI/CD automation
  • Webhooks remove manual deployment steps
  • EC2 provides full control (SSH, configs)

4️⃣ Terraform Infrastructure Breakdown

4.1 EC2 Instances Created

  • EC2 #1: Website Server (NGINX installed via user-data)
  • EC2 #2: Jenkins Server

4.2 Important Security Groups

  • Port 22 → SSH
  • Port 80 → Website
  • Port 8080 → Jenkins UI

4.3 Terraform Outputs

jenkins_public_ip
website_public_ip

These make it easy to access both servers.

5️⃣ NGINX Website Deployment

Your static website files (HTML/CSS/JS) live here:

/var/www/html

Jenkins will delete old files and upload new ones on every code push.

6️⃣ Jenkins CI/CD Pipeline

Stage 1 – Checkout Code

git url: 'https://github.com/your-repo'

Stage 2 – Deploy to EC2

ssh -o StrictHostKeyChecking=no ubuntu@SERVER_IP '
  sudo rm -rf /var/www/html/*
  sudo git clone YOUR_REPO /var/www/html
  sudo systemctl restart nginx
'

Once the pipeline finishes, the website updates instantly.

7️⃣ GitHub Webhook

http://<JENKINS_IP>:8080/github-webhook/

Triggers Jenkins automatically.

8️⃣ Verification

Check website:

http://<WEBSITE_PUBLIC_IP>

Check Jenkins:

http://<JENKINS_PUBLIC_IP>:8080

9️⃣ Conclusion

With just Terraform + Jenkins + AWS EC2, you can build a complete CI/CD pipeline that updates your live website every time you push code to GitHub.

  • No manual deployment
  • Fast updates
  • Production-style automation

✨ Connect With Me

Author: Mahesh Shelke

GitHub: github.com/Maheshshelke05
LinkedIn: linkedin.com/in/mahesh-shelke-7497a7315
Medium: medium.com/@maheshshelke05