Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions host
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[jenkins-master]
10.1.1.78

[jenkins-master:vars]
ansible_user=ubuntu
ansible_ssh_private_key_file=/opt/dppa.pem

[jenkins-slave]
10.1.1.18

[jenkins-slave:vars]
ansible_user=ubuntu
ansible_ssh_private_key_file=/opt/dppa.pem

34 changes: 34 additions & 0 deletions jenkins-master-setup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
- host: jenkins-master
become: true
tasks:
- name: add jenkins key
apt_key:
url: https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
state: present

- name: add jenkins repo
apt_repository:
repo: 'deb https://pkg.jenkins.io/debian-stable binary/'
state: present

- name: install java
apt:
name: openjdk-17-jre
state: present

- name: install jenkins
apt:
name: jenkins
state: present

- name: start jenkins service
service:
name:
state: started

- name: enable jenkins to start at boot time
service:
name: jenkins
enable: yes

9 changes: 0 additions & 9 deletions terraform_code/V1-EC2.tf

This file was deleted.

36 changes: 0 additions & 36 deletions terraform_code/V2-EC2.tf

This file was deleted.

93 changes: 0 additions & 93 deletions terraform_code/V3-EC2-With_VPC.tf

This file was deleted.

100 changes: 52 additions & 48 deletions terraform_code/V4-EC2-With_VPC_for_each.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,34 @@ provider "aws" {
}

resource "aws_instance" "demo-server" {
ami = "ami-053b0d53c279acc90"
instance_type = "t2.micro"
key_name = "dpp"
//security_groups = [ "demo-sg" ]
vpc_security_group_ids = [aws_security_group.demo-sg.id]
subnet_id = aws_subnet.dpp-public-subnet-01.id
for_each = toset(["jenkins-master", "build-slave", "ansible"])
tags = {
Name = "${each.key}"
}
}
ami = "ami-0c7217cdde317cfec"
instance_type = "t2.micro"

key_name = "dppa"
//security_groups = [ "demo-sg" ]
vpc_security_group_ids = [aws_security_group.demo-sg.id]
subnet_id = aws_subnet.dppa-public_subent_01.id

for_each = toset(["jenkins-master", "build-slave", "ansible"])
tags = {
Name = "${each.key}"
}

}
resource "aws_security_group" "demo-sg" {
name = "demo-sg"
description = "SSH Access"
vpc_id = aws_vpc.dpp-vpc.id
vpc_id = aws_vpc.dppa-vpc.id

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

ingress {
ingress {
description = "Jenkins port"
from_port = 8080
to_port = 8080
Expand All @@ -45,60 +47,62 @@ resource "aws_security_group" "demo-sg" {
}

tags = {
Name = "ssh-prot"

Name = "ssh-port"
}
}

resource "aws_vpc" "dpp-vpc" {
resource "aws_vpc" "dppa-vpc" {
cidr_block = "10.1.0.0/16"
tags = {
Name = "dpp-vpc"
Name = "dppa-vpc"
}

}

resource "aws_subnet" "dpp-public-subnet-01" {
vpc_id = aws_vpc.dpp-vpc.id
cidr_block = "10.1.1.0/24"
resource "aws_subnet" "dppa-public_subent_01" {
vpc_id = aws_vpc.dppa-vpc.id
cidr_block = "10.1.1.0/24"
map_public_ip_on_launch = "true"
availability_zone = "us-east-1a"
availability_zone = "us-east-1a"
tags = {
Name = "dpp-public-subent-01"
Name = "dppa-public_subent_01"
}
}

resource "aws_subnet" "dpp-public-subnet-02" {
vpc_id = aws_vpc.dpp-vpc.id
cidr_block = "10.1.2.0/24"
resource "aws_subnet" "dppa-public_subent_02" {
vpc_id = aws_vpc.dppa-vpc.id
cidr_block = "10.1.2.0/24"
map_public_ip_on_launch = "true"
availability_zone = "us-east-1b"
availability_zone = "us-east-1b"
tags = {
Name = "dpp-public-subent-02"
Name = "dppa-public_subent_02"
}
}

resource "aws_internet_gateway" "dpp-igw" {
vpc_id = aws_vpc.dpp-vpc.id
resource "aws_internet_gateway" "dppa-igw" {
vpc_id = aws_vpc.dppa-vpc.id
tags = {
Name = "dpp-igw"
}
Name = "dppa-igw"
}
}

resource "aws_route_table" "dpp-public-rt" {
vpc_id = aws_vpc.dpp-vpc.id
resource "aws_route_table" "dppa-public-rt" {
vpc_id = aws_vpc.dppa-vpc.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.dpp-igw.id
gateway_id = aws_internet_gateway.dppa-igw.id
}
tags = {
Name = "dppa -public-rt"
}
}

resource "aws_route_table_association" "dpp-rta-public-subnet-01" {
subnet_id = aws_subnet.dpp-public-subnet-01.id
route_table_id = aws_route_table.dpp-public-rt.id
resource "aws_route_table_association" "dppa-rta-public-subent-1" {
subnet_id = aws_subnet.dppa-public_subent_01.id
route_table_id = aws_route_table.dppa-public-rt.id
}

resource "aws_route_table_association" "dpp-rta-public-subnet-02" {
subnet_id = aws_subnet.dpp-public-subnet-02.id
route_table_id = aws_route_table.dpp-public-rt.id

resource "aws_route_table_association" "dppa-rta-public-subent-2" {
subnet_id = aws_subnet.dppa-public_subent_02.id
route_table_id = aws_route_table.dppa-public-rt.id
}
7 changes: 7 additions & 0 deletions terraform_code/dppa.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtz
c2gtZWQyNTUxOQAAACDY8Yb0OIGvcpQ3qyfvwxxICepvTkCqxkvYoEh3b5J48wAA
AIgM147lDNeO5QAAAAtzc2gtZWQyNTUxOQAAACDY8Yb0OIGvcpQ3qyfvwxxICepv
TkCqxkvYoEh3b5J48wAAAEAwUQIBATAFBgMrZXAEIgQgUWhRWDfVAHUQtAaxVU0w
rdjxhvQ4ga9ylDerJ+/DHEgJ6m9OQKrGS9igSHdvknjzAAAAAAECAwQF
-----END OPENSSH PRIVATE KEY-----