DEV Community

Vivesh
Vivesh

Posted on

Terraform-Jenkins-CICD

_

Writing is often an overlooked skill in tech, but it plays a crucial role in how we communicate and collaborate. Through Hacktoberfest’s writing challenges, I can contribute in ways that aren’t just about code but also about fostering community, clarifying complex ideas, and supporting fellow developers by creating accessible content.
It’s a different kind of contribution, but just as valuable—and I’m excited to be a part of it._

Project Overview:

_

In this project, we set up an infrastructure to automate the deployment of a static website using AWS S3 and Terraform. The project is managed through a Jenkins CI/CD pipeline and includes security measures like state locking with DynamoDB and resource provisioning using Terraform scripts. The setup also leverages Docker and Sonarqube for quality analysis and scanning, along with Trivy for vulnerability scanning.
_

Key Components

  1. Terraform and Jenkins Setup Terraform: Used to define infrastructure as code, provisioning AWS resources like EC2 instances, S3 buckets, and DynamoDB tables. Jenkins: Set up on an AWS EC2 instance (Ubuntu 22.04, T2 Large) for CI/CD automation. Jenkins manages code deployment, infrastructure setup, and code quality checks.
  2. S3 Bucket for Static Website Hosting Created an S3 bucket using Terraform to host a static website. User Data: Utilized a startup script to launch containers and configure the website during EC2 instance provisioning.
  3. Infrastructure State Management S3 was used to store Terraform state files securely. DynamoDB was set up for state locking to prevent simultaneous state changes during Terraform executions.
  4. IAM Roles and Permissions Created an IAM Role with permissions for EC2, S3, and DynamoDB to allow Jenkins to interact with AWS resources.
  5. CI/CD Pipeline Using Jenkins Installed Docker, Trivy, and SonarQube in the Jenkins environment for containerization, security scanning, and code quality analysis. The Jenkins pipeline automates the following tasks: Checkout code from GitHub SCM. SonarQube analysis to ensure code quality. Trivy security scan of Docker images. Terraform commands for infrastructure deployment (init, plan, apply). Example Terraform configuration files: backend.tf for managing remote states. s3.tf, variables.tf, provider.tf, and main.tf for defining AWS resources. website.sh, index.html, style.css, and script.js for website setup.
  6. Tools & Plugins Installed Terraform: Installed via Jenkins Global Tool Configuration. SonarQube Scanner: Configured in Jenkins for static code analysis. Trivy: Installed for vulnerability scanning.

Methodologies Implemented

  • Infrastructure as Code (IaC): Used Terraform to define and manage infrastructure in a repeatable manner.
  • CI/CD Automation: Implemented a Jenkins pipeline for continuous integration and delivery.
  • Security and Compliance: Utilized tools like SonarQube and Trivy to ensure code quality and container security.
  • State Management: Used S3 and DynamoDB to manage and lock Terraform state files.

View GitHub Source Code

Top comments (0)