Create SonarQube instance using Terraform - Setup SonarQube instance using Terraform

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

1. sudo vi sonar.tf if you are using Apple laptop

for Windows laptop use below command:

notepad sonar.tf

2. Copy the below content with green background:

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

    resource "aws_instance" "myFirstInstance_sonar" {
      ami           = "ami-916f59f4"

      key_name = "ChangeMeKey"
      instance_type = "t2.micro"
      security_groups= [ "security_sonar_group_2019"]
      tags= {
        Name = "sonar_instance"
      }
    }
 resource "aws_security_group" "security_sonar_group_2019" {
      name        = "security_sonar_group_2019"
      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"
      }
    }

3.  execute below command:
    terraform plan
4. and then
    terraform apply

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

Post a Comment

0 Comments