AWS EC2 with Jenkins and SonarQube [Dynamic block used]

This project automates the creation of AWS resources using Terraform, focusing on EC2 instances. Jenkins and SonarQube are incorporated for continuous integration and code quality checks in a DevOps.

Perquisites:

Installed to be on your Local Machine.

For Installing All for this , Follow the Official Document of that tools.

Terraform VS Code Aws CLI Aws Account

Install Terraform

You have to install Terraform on your local machine. You can download it from the official Terraform website (https://www.terraform.io/downloads.htmlarrow-up-right) and follow the installation instructions for your operating system.

Then we need to create a user on the AWS and after creating the user , generate the Access & Secrete Access Key, for the connecting the AWS with Terraform.

after Creating the user we need to some access/permissions to this user. creating & managing the terraform permissions or provide the aws Administrator permissions/access.

Create a user on the aws

Configure AWS Credentials:

provider.tf

The provider.tf file is used to define the provider configuration. A Terraform provider is responsible for managing the lifecycle of a particular type of infrastructure, such as AWS, Azure, Google Cloud, etc. It specifies the details of the cloud provider you are using and any necessary authentication or configuration parameters.

main.tf

The main.tf file is typically the main entry point for your Terraform configuration. It contains the resource definitions and configurations necessary for your infrastructure. In the context of provisioning AWS EKS with Terraform, it would include the definition of your EKS cluster, associated networking resources, and any other dependencies.

Terraform init

Run the command in your Terraform project directory to initialize the project. This downloads the necessary provider plugins and sets up the working directory.

terraform.lock.hcl File:

The terraform.lock.hcl file is related to Terraform modules and is used to pin module versions. It's created automatically when you use the terraform init command to initialize a Terraform configuration that uses modules.

terraform validate

The terraform validate command checks the syntax and structure of your Terraform configuration files. It ensures that your configurations are correctly written and that all the necessary providers and modules are available.

terraform plan

The terraform plan command is used to create an execution plan. It provides a preview of the changes that Terraform will make to your infrastructure based on your configuration. This is a critical step before actually applying any changes to your infrastructure.

terraform apply

Apply the Terraform configuration to create the AWS resources. This step might take some time as it provisions the EKS cluster, associated networking resources, and other dependencies.

Output - Running the ec2

terraform destroy

This Command for destroy all of those resources , which was created by terraform.

After destroy command . server willl be Terminated

Edit the main.tf file for the use of dynamic Block

Dynamic blocks provide a way to generate repeated configurations dynamically within a resource block. They allow you to handle situations where you need to create multiple resources of a nested block with varying configurations.

Here, the situation is ,In this File ( OLD FILE ) we have to generate repeated configurations of ingress, So that's why, we are using dynamic block here.

main.tf -- using Dynamic Block

Install.sh

Install.sh is script file , Script for Terraform would be designed to automate the installation process

This file are used for running the Script for installation of the Jenkins , Docker ,& SonarQube

Script of Install.sh

terraform validate

terraform plan

terraform apply

EC2 instance Running

Docker & SonarQube running

SonarQube Console

Jenkins Interface

terraform destroy

This Command for destroy all of those resources , which was created by terraform.

Last updated