Sunday, October 21, 2018

Create SonarQube instance using Terraform - Setup SonarQube instance using Terraform

Execute the below command after login to EC2 where you installed Terraform:

navigate to project-terraform folder where you have created already tf files.

cd ~/project-terraform

if you are using Apple laptop or EC2 instance, execute below command:

sudo vi sonar.tf 

for Windows laptop use below command:

notepad sonar.tf

Copy the below content with green background:

Change the key name marked red below per your key name:

resource "aws_vpc" "sonar" {
  cidr_block = "172.16.0.0/16"
  instance_tenancy = "default"
  tags = {
    Name = "sonar_vpc"
  }
}

 resource "aws_security_group" "security_sonar_group_2023" {
      name        = "security_sonar_group_2023"
      description = "security group for Sonar"
      ingress {
        from_port   = 9000
        to_port     = 9000
        protocol    = "tcp"
        cidr_blocks = ["0.0.0.0/0"]
      }

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

     # outbound from Sonar server
      egress {
        from_port   = 0
        to_port     = 65535
        protocol    = "tcp"
        cidr_blocks = ["0.0.0.0/0"]
      }

      tags= {
        Name = "security_sonar"
      }
    }

    resource "aws_instance" "mySonarInstance" {
      ami           = "
ami-0b9064170e32bde34"
      key_name = "your_aws_ssh_key"
      instance_type = "t2.micro"
      
vpc_security_group_ids = [aws_security_group.security_sonar_group_2023.id]

      tags= {
        Name = "sonar_instance"
      }
    }

# Create Elastic IP address for Sonar instance
resource "aws_eip" "mySonarInstance" {
  vpc      = true
  instance = aws_instance.mySonarInstance.id
tags= {
    Name = "sonar_elastic_ip"
  }
}

Execute below command:
    terraform plan
and then
    terraform apply

Now you will see a new EC2 instance being created in AWS console.

4 comments:

  1. According to SEO experts, they help business owners deliver their sites to top rank search engines. click to read This is because a recent research on SEO returns for a period of 12 months shows that at least all the players had something to take home.

    ReplyDelete
    Replies
    1. Creating a SonarQube instance is an important step in improving code quality, security analysis, and continuous inspection within modern DevOps and software development environments. SonarQube helps developers automatically detect bugs, vulnerabilities, code smells, and maintainability issues across multiple programming languages and enterprise applications. Integrating SonarQube into CI/CD pipelines enables teams to monitor software quality continuously and enforce coding standards during development and deployment processes. Technologies such as Docker, Jenkins, Kubernetes, and cloud infrastructure are commonly used to deploy scalable SonarQube environments efficiently. Students and developers interested in modern software engineering and automation workflows can explore Web Development Projects to gain practical knowledge about enterprise application development, CI/CD integration, and scalable deployment architectures.

      Delete
    2. Modern DevOps ecosystems increasingly rely on automated testing, code analysis, infrastructure automation, and cloud-native deployment strategies to improve software reliability and development efficiency. SonarQube plays a major role in maintaining secure and high-quality applications by supporting static code analysis, technical debt management, and real-time project quality monitoring. Understanding these tools helps students build robust software delivery pipelines and secure development environments for enterprise systems. Learners who want to strengthen their expertise in scalable cloud infrastructures and secure deployment practices can also refer to Cloud Computing Projects to explore intelligent cloud-based systems and distributed application management technologies used in modern software industries.

      Delete