MFH Modernisation


Development Overview Diagram

Workflow Diagram :

Dev Infra Diagram:

Steps for Dev Infra :

  • create aws CLI credentials for creating infra and storing the state file
  • add credentials in github secrets as AWS_ACCESS_KEY and AWS_SECRET_ACCESS_KEY
  • Below is the code for creating dev infra using terraform

provider.tf

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }

   backend "s3" {
     bucket = "futuiontech-terraform"
     key    = ".terraform.tfstate"
     region = "ap-south-1"
   }
}

provider "aws" {
  region = "ap-south-1"
}

ec2.tf

resource "aws_instance" "web"{
  ami           = "ami-0f5ee92e2d63afc18"
  instance_type = "t2.micro"

  tags = {
    Name = "ec2"
  }
  user_data = file("ubuntu.sh")
}

ecr.tf

resource "aws_ecr_repository" "ecr" {
  name                 = "futuiontech"
  image_tag_mutability = "MUTABLE"

  image_scanning_configuration {
    scan_on_push = true
  }
}

rds.tf

resource "aws_db_instance" "default" {
  allocated_storage    = 10
  db_name              = "mydb"
  engine               = "mysql"
  engine_version       = "5.7"
  instance_class       = "db.t3.micro"
  username             = "admin"
  password             = "mypassword"
  parameter_group_name = "default.mysql5.7"
  skip_final_snapshot  = true
}

ubuntu.sh

#! /bin/bash
sudo apt update
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu  $(lsb_release -cs)  stable"
sudo apt update
sudo apt-get install docker-ce
sudo systemctl start docker
sudo systemctl enable docker
sudo groupadd docker
sudo usermod -aG docker ubuntu

github-actions.yaml

name: Terraform GitHub Actions

on:
   push:
    branches: [main]
jobs:
  Deploy_Resources:
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout Code
        uses: actions/checkout@v2
      - name: AWS Credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: us-east-1
      
      - name: Terraform Install
        uses: hashicorp/setup-terraform@v1
      - name: Terraform fmt
        id: fmt
        run: | 
          terraform --version
          terraform fmt
        continue-on-error: true
        
      - name: Terraform Init
        id: init
        run: terraform init
        
      - name: Terraform Validate
        id: validate
        run: terraform validate -no-color  
        
      - name: Terraform Plan
        id: plan
        run: terraform plan -no-color
        continue-on-error: true
        
      - name: Terraform Apply
        id: Apply
        run: terraform apply -auto-approve
        continue-on-error: true
        
      - name: Terraform Destroy
        id: Destory
        run: terraform destroy -auto-approve
        continue-on-error: true
        

LMS Link :

Project Tracker :

Leave a Comment

MFH IT Solutions (Regd No -LIN : AP-03-46-003-03147775)

Consultation & project support organization.

Contact

MFH IT Solutions (Regd)
NAD Kotha Road, Opp Bashyam School, Butchurajupalem, Jaya Prakash Nagar Visakhapatnam, Andhra Pradesh – 530027