-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsonarqube.tf
59 lines (45 loc) · 1.81 KB
/
sonarqube.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
module "SonarQube_ec2_instance" {
source = "terraform-aws-modules/ec2-instance/aws"
name = "SonarQube"
instance_type = "t2.medium"
key_name = var.key_name # key name as variable
monitoring = false
count = 1 # Number of instances
ami = "ami-04a81a99f5ec58529"
root_block_device = [
{
volume_size = 20
}
]
user_data = <<-EOF
#!/bin/bash
# Update package manager repositories
sudo apt-get update -y
# Install necessary dependencies
sudo apt-get install -y wget zip ca-certificates curl
# Update package manager repositories
sudo apt-get update
# Add Docker's official GPG key
sudo apt-get update
sudo apt-get install -y ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the Docker repository to Apt sources
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
# Install Docker
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo chmod 666 /var/run/docker.sock
#run SonarQube server on docker
docker run -d --name sonar -p 9000:9000 sonarqube:lts-community
EOF
vpc_security_group_ids = [aws_security_group.sonarqube_sg.id]
tags = {
Terraform = "true"
Environment = "dev"
}
}
output "sonarqube_instance_public_ip" {
value = module.SonarQube_ec2_instance[0].public_ip
}