Skip to content

Commit

Permalink
added jenkins installation script
Browse files Browse the repository at this point in the history
  • Loading branch information
chefgs committed Aug 19, 2024
1 parent c8b2b4c commit 51cdda9
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 8 deletions.
1 change: 1 addition & 0 deletions tf-ec2-with-modules/terraform-project/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ module "ec2" {
subnet_id = module.subnet.subnet_id
security_group_id = module.security_group.security_group_id
key_name = var.key_name
user_data = file("${var.user_data}")
}
1 change: 1 addition & 0 deletions tf-ec2-with-modules/terraform-project/modules/ec2/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ resource "aws_instance" "main" {
subnet_id = var.subnet_id
security_groups = [var.security_group_id]
key_name = var.key_name
user_data = var.user_data

tags = {
Name = "MyEC2Instance"
Expand Down
4 changes: 4 additions & 0 deletions tf-ec2-with-modules/terraform-project/modules/ec2/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
output "instance_id" {
value = aws_instance.main.id
}

output "instance_public_ip" {
value = aws_instance.main.public_ip
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ variable "security_group_id" {
variable "key_name" {
description = "value of the key pair"
type = string
}

variable "user_data" {
description = "filename of userdata file"
type = string
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@ resource "aws_security_group" "main" {
vpc_id = var.vpc_id

ingress {
from_port = 22
to_port = 22
description = "Allow Jenkins traffic"
from_port = 8080
to_port = 8080
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"] # Allows access from anywhere
}

ingress {
description = "Allow HTTP traffic"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
cidr_blocks = ["0.0.0.0/0"] # Allows access from anywhere
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
ingress {
description = "Allow SSH traffic"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"] # Adjust for more security if needed
}

tags = {
Expand Down
3 changes: 3 additions & 0 deletions tf-ec2-with-modules/terraform-project/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
output "instance_id" {
value = module.ec2.instance_id
}
output "instance_public_ip" {
value = module.ec2.instance_public_ip
}
26 changes: 26 additions & 0 deletions tf-ec2-with-modules/terraform-project/scripts/install-jenkins.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Update the package index
sudo yum update -y

# Install Java 11 (required for Jenkins)
sudo amazon-linux-extras install java-openjdk11 -y

# Enable the Jenkins repository
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo

# Import the Jenkins package signing key
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key

# Install Jenkins
sudo yum install jenkins -y

# Start the Jenkins service
sudo systemctl start jenkins

# Enable Jenkins to start on system boot
sudo systemctl enable jenkins

# Print the Jenkins initial admin password
echo "Jenkins initial admin password:"
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
5 changes: 5 additions & 0 deletions tf-ec2-with-modules/terraform-project/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ variable "key_name" {
default = "your-pem-key-name"
}

variable "user_data" {
description = "filename of userdata file"
type = string
default = "userdata.sh"
}

0 comments on commit 51cdda9

Please sign in to comment.