This project is used to deploy Infrastructure like VPC,subnets through terraform and automating it with the help of Jenkins CI/CD pipeline.
This Project contains a full, real-world solution for setting up an environment using DevOps technologies and practices for deploying cloud services/cloud infrastructure like Virtual Private Cloud to AWS.
You will be using the following technologies and platforms to set up a DevOps environment.
- AWS
- AWS will be used to host the application, cloud infrastructure, and any other services we may need to ensure the VPC is deployed properly.
- GitHub
- To store the application and infrastructure/automation code
- Terraform
- To automate the infrastructure deployment on AWS
- Jenkins CI/CD
- Used Jenkins to create CI and CD pipeline
- Git bash
- This tool is ues to SSH in EC2 instance and to push local files to git hub
- AWS EC2 linux/ubuntu instance
- Configure Jenkins on the AWS instance by following the steps mentioned here
- Install necessay plugin on Jenkins like Terraform, Github.
- Install Terraform on the same EC2 instance by following the steps mentioned here
- Install git on the instance by
sudo yum install git -y
- Integrate/Configure Github with Jenkins by following the steps here
- Create an IAM role with full administrative access and attach it to the EC2 instance.
git init -x main
git add .
git commit -x "initial commit"
git remote add origin <REMOTE_URL>
git remote -v
git push origin main/master
- Create a new pipeline Project in Jenkins
- Mentioned the stages in the groovy script
pipeline{
agent any
tools {
terraform 'terraform-11'
}
stages{
stage('Git Checkout'){
steps{
git credentialsId: '30c1c3e9-2949-4138-971d-xxxxxxxx', url: 'https://github.com/tanuj888/Terraform-with-CI-CD'
}
}
stage('Terraform init'){
steps{
sh 'terraform init'
}
}
stage('Terraform Apply'){
steps{
sh 'terraform apply --auto-approve'
}
}
stage('Terraform Destroy'){
steps{
sh 'terraform destroy --auto-approve'
}
}
}
}
-
As soon you hit save, click on build now to build this pipeline.
-
Go to your AWS Console and you'll find a new VPC created.
-
Clean Up Resources
- Add a step Terraform destroy in the pipeline as mentioned in the scipt above which will destroy the created infrastructure.