Skip to content

padmashri23/CI-CD_Integration_with_Crypto_Price_Tracking_app

Repository files navigation

CI/CD Integration with Crypto Price Tracking App

πŸ“€ Automatically Apply Terraform with AWS EC2 Instance

🌍 Why Terraform?

Terraform is a powerful Infrastructure as Code (IaC) tool that enables efficient, scalable, and automated infrastructure management. Here's why it stands out:

βœ… Key Benefits of Terraform Over Manual Setup

βœ”οΈ Infrastructure is repeatable & consistent

βœ”οΈ Fast, automated deployment

βœ”οΈ Easily scales with configurations

βœ”οΈ Changes are tracked in Git

βœ”οΈ Easier rollback in case of issues

βœ”οΈ Teams can collaborate via code

Using Terraform with your CI/CD pipeline ensures stability, visibility, and productivityβ€”especially when deploying modern apps like React.js on AWS EC2.

πŸš€ Deploying a React.js App on AWS EC2 Using Terraform

πŸ“ Architecture Diagram

Architecture Diagram


β˜‘οΈ Steps

  1. Clone React.js App from GitHub
  2. Create an IAM User
  3. Configure AWS Profile and Set Up the AWS CLI
  4. Set Up Terraform Configuration
  5. Deploy the Infrastructure with Terraform
  6. Clean Up Resources

🀸 Quick Start

Prerequisites

Ensure the following tools are installed on your system:


🐼 Cloning the Repository

git clone https://github.com/padmashri23/CI-CD_Integration_with_Crypto_Price_Tracking_app.git

βž” Step 1 - Create an IAM User and Access Key

  1. Navigate to the AWS Console > IAM > Users > Create user
  2. Enter user name (e.g., ec2-terraform) and proceed
  3. Attach the following policies:
    • AmazonEC2FullAccess
    • AdministratorAccess
  4. Complete creation and generate access keys
  5. Choose "CLI" as the usage type and download the CSV credentials file

βž” Step 2 - Configure AWS CLI

  1. Open your IDE and create a directory:
mkdir aws-ec2-terraform && cd aws-ec2-terraform
  1. Run AWS configuration:
aws configure
  1. Input your credentials and region when prompted

  2. Verify configuration:

aws configure list

βž” Step 3 - Set Up Terraform Configuration

  1. Create a Terraform configuration file:
touch main.tf
  1. Add the following content to main.tf:
provider "aws" {
  region = "us-east-1"
}

resource "aws_instance" "react_app" {
  ami           = "ami-xxxxxxxxxxxx"  # Update with valid Amazon Linux 2 AMI ID
  instance_type = "t2.micro"
  security_groups = [aws_security_group.react_sg.name]

  user_data = <<-EOF
              #!/bin/bash
              sudo yum update -y
              sudo amazon-linux-extras enable nginx1
              sudo yum install -y nginx
              sudo systemctl start nginx
              sudo systemctl enable nginx

              curl -fsSL https://rpm.nodesource.com/setup_18.x | sudo bash -
              sudo yum install -y nodejs
              sudo yum install -y git

              git clone https://github.com/yourusername/your-react-app.git /home/ec2-user/react-app
              cd /home/ec2-user/react-app
              npm install && npm run build

              sudo rm -rf /usr/share/nginx/html/*
              sudo cp -r /home/ec2-user/react-app/dist/* /usr/share/nginx/html/
              sudo systemctl restart nginx
              EOF

  tags = {
    Name = "ReactAppServer"
  }
}

resource "aws_security_group" "react_sg" {
  name        = "react_app_sg"
  description = "Allow HTTP and SSH access"

  ingress {
    from_port   = 22
    to_port     = 22
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }

  ingress {
    from_port   = 80
    to_port     = 80
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }

  egress {
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }
}

Note: Replace https://github.com/yourusername/your-react-app.git with your repository URL.


βž” Step 4 - Deploy Infrastructure

  1. Initialize Terraform:
terraform init
  1. Plan and Apply:
terraform apply -auto-approve
  1. Access the App:

Visit your EC2 public IP in a browser:

http://your-ec2-public-ip

You should see your React.js app live! πŸš€


πŸ–³οΈ Clean Up Resources

terraform destroy

πŸ“… Final Results

Result 1 Result 2 Result 3 Result 4


App Running on:

http://54.226.0.98


πŸ“„ Reference Tutorial

Tutorial Video

πŸš€ Make sure to install AWS CLI and Terraform CLI before beginning your setup.

Releases

No releases published

Packages

No packages published