Git Product home page Git Product logo

abrar-2510 / aws-terraform-jenkins Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 82 KB

This repository provides Terraform code for building a basic AWS infrastructure. It includes setting up a virtual network with public and private subnets, launching EC2 servers in both types of subnets, and configuring database (RDS) and in-memory data store (ElastiCache) services.

HCL 82.73% Dockerfile 7.28% Python 9.99%
ansible aws awslamda awss3 jenkins terraform

aws-terraform-jenkins's Introduction

Deploying AWS Infrastructure with Terraform and Jenkins

infra

Overview

Networking

  • create vpc
  • create internet gateway
  • create public route table
  • create private route table
  • create public route
  • attach public route table to subnets

Computing

  • create security group which allow ssh from 0.0.0.0/0
  • create security group that allow ssh and port 3000 from vpc cidr only
  • create ec2(bastion) in public subnet with security group from 7
  • create ec2(application) private subnet with security group from 8
  • create two workspaces terraform and production
  • create two variable definition files(.tfvars) for the two environments
  • separate network resources into network module
  • apply your code to create two environments one in us-east-1 and eu-central-1
  • run local-exec provisioner to print the public_ip of bastion ec2
  • upload infrastructure code on github project
  • create jenkins image with terraform installed inside it
  • create pipeline that takes env-param to apply terraform code on certain env
  • verify your email in ses service
  • create lambda function to send email
  • create trigger to detect changes in state file and send the email

Database

  • create rds
  • create elastic cache
  • use jenkins to deploy node js app on the application ec2
  • Development

    Configure your AWS access keys.

    [default]
    aws_access_key_id = <your_access_key_id>
    aws_secret_access_key = <your_secret_access_key>

    Create the 2 workspaces

    $ terraform workspace new production
    $ terraform workspace new terraform

    Initialize working directory to download the necessary Terraform plugins..

    [default]
    terraform init

    to create the Bastion host and security group run:

    [default]
    terraform apply

    Once the Bastion host has been created, you can connect to it using SSH. The Bastion host will be assigned a public IP address, which you can use to connect to it from the public internet. For example:

    ssh -i /path/to/private/key ec2-user@<bastion-public-ip>

    Replace /path/to/private/key with the path to your private SSH key, and with the public IP address of the Bastion host.

    using jenkins

    build the custom image that contains ansible and docker client

    cd jenkins
    docker build -t <imageName> -f jenkins_master.dockerfile .
    

    run the image

    docker run --name <containerName> -p8080:8080 -d -v /var/run/docker.sock:/var/run/docker.sock  -v /usr/bin/terraform:/usr/bin/terraform <imageName>
    

    for jenkins master at http://localhost:8080/

    Jenkins Pipeline Process

    1- Add AWS Credentials to Jenkins

    Navigate to "Manage Jenkins". Select "Manage Credentials". Add a new "AWS Credentials" entry with the necessary access key and secret key.

    2- Create a Parameterized Pipeline

    Go to "New Item". Enter a name for your pipeline and select "Pipeline". In the pipeline configuration, check "This project is parameterized". Add a choice parameter named ACTION with options like apply and destroy.

    3- Build the Infrastructure (Choose Apply) In the pipeline script, include logic to handle the apply action using Terraform or any relevant tool. Trigger the build and select "apply" when prompted.

    4- Create a New Node Navigate to "Manage Nodes and Clouds". Click on "New Node". Enter a name for the new node and select the appropriate node type (e.g., "Permanent Agent"). Configure the node settings, including remote root directory and launch method.

    5- Create a New Pipeline for the Application Go to "New Item" again. Enter a name for the application pipeline and select "Pipeline". Configure the pipeline as required, including SCM settings and build triggers.

    6- Build the Pipeline Again and Choose Destroy Trigger the application pipeline build. When prompted, select "destroy" to tear down the infrastructure.

    aws-terraform-jenkins's People

    Contributors

    abrar-2510 avatar

    Stargazers

     avatar

    Watchers

     avatar

    Recommend Projects

    • React photo React

      A declarative, efficient, and flexible JavaScript library for building user interfaces.

    • Vue.js photo Vue.js

      ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

    • Typescript photo Typescript

      TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

    • TensorFlow photo TensorFlow

      An Open Source Machine Learning Framework for Everyone

    • Django photo Django

      The Web framework for perfectionists with deadlines.

    • D3 photo D3

      Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

    Recommend Topics

    • javascript

      JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

    • web

      Some thing interesting about web. New door for the world.

    • server

      A server is a program made to process requests and deliver data to clients.

    • Machine learning

      Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

    • Game

      Some thing interesting about game, make everyone happy.

    Recommend Org

    • Facebook photo Facebook

      We are working to build community through open source technology. NB: members must have two-factor auth.

    • Microsoft photo Microsoft

      Open source projects and samples from Microsoft.

    • Google photo Google

      Google โค๏ธ Open Source for everyone.

    • D3 photo D3

      Data-Driven Documents codes.