Skip to content

Commit

Permalink
updated ubuntu scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
chefgs committed Sep 1, 2024
1 parent 67badb6 commit 324d051
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 19 deletions.
32 changes: 32 additions & 0 deletions tf-ec2-with-modules/terraform-project/ami.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
data "aws_ami" "amazon_linux" {
most_recent = true

filter {
name = "name"
values = ["amzn2-ami-hvm-*-x86_64-gp2"]

}

filter {
name = "virtualization-type"
values = ["hvm"]
}

owners = ["amazon"]
}

data "aws_ami" "ubuntu_linux" {
most_recent = true

filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*", "ubuntu/images/hvm-ssd/ubuntu-lunar-24.04-amd64-server-*"]
}

filter {
name = "virtualization-type"
values = ["hvm"]
}

owners = ["amazon"]
}
19 changes: 1 addition & 18 deletions tf-ec2-with-modules/terraform-project/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,9 @@ module "security_group" {
vpc_id = module.vpc.vpc_id
}


data "aws_ami" "example" {
most_recent = true

filter {
name = "name"
values = ["amzn2-ami-hvm-*-x86_64-gp2"]
}

filter {
name = "virtualization-type"
values = ["hvm"]
}

owners = ["amazon"]
}

module "ec2" {
source = "./modules/ec2"
ami = data.aws_ami.example.id
ami = data.aws_ami.ubuntu_linux.id
instance_type = "t2.micro"
subnet_id = module.subnet.subnet_id
security_group_id = module.security_group.security_group_id
Expand Down
32 changes: 32 additions & 0 deletions tf-ec2-with-modules/terraform-project/modules/ec2/ami.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
data "aws_ami" "amazon_linux" {
most_recent = true

filter {
name = "name"
values = ["amzn2-ami-hvm-*-x86_64-gp2"]

}

filter {
name = "virtualization-type"
values = ["hvm"]
}

owners = ["amazon"]
}

data "aws_ami" "ubuntu_linux" {
most_recent = true

filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*", "ubuntu/images/hvm-ssd/ubuntu-lunar-24.04-amd64-server-*"]
}

filter {
name = "virtualization-type"
values = ["hvm"]
}

owners = ["amazon"]
}
2 changes: 1 addition & 1 deletion tf-ec2-with-modules/terraform-project/modules/ec2/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "aws_instance" "main" {
ami = var.ami
ami = data.aws_ami.ubuntu_linux.id
instance_type = var.instance_type
subnet_id = var.subnet_id
security_groups = [var.security_group_id]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

# Update the package index
sudo apt-get update -y

# Install Java 17 (latest stable version required for Jenkins)
sudo apt-get install openjdk-17-jdk -y

# Set JAVA_HOME environment variable
echo "export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64" | sudo tee -a /etc/profile
echo "export PATH=\$JAVA_HOME/bin:\$PATH" | sudo tee -a /etc/profile
source /etc/profile

# Enable the Jenkins repository
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'

# Update the package index again
sudo apt-get update -y

# Install Jenkins
sudo apt-get install jenkins -y

# Start the Jenkins service
sudo systemctl start jenkins

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

# Wait for Jenkins to complete setup
echo "Waiting for Jenkins to complete setup..."
while [ ! -f /var/lib/jenkins/secrets/initialAdminPassword ]; do
sleep 10
done

# Print the Jenkins initial admin password
echo "Jenkins initial admin password:"
sudo cat /var/lib/jenkins/secrets/initialAdminPassword

0 comments on commit 324d051

Please sign in to comment.