Skip to content

Commit e75ea44

Browse files
committed
Update
1 parent 8b79fe9 commit e75ea44

File tree

7 files changed

+306
-0
lines changed

7 files changed

+306
-0
lines changed

01-AWS-EC2/main.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
}
6+
}
7+
}
8+
9+
provider "aws" {
10+
region = "us-east-1"
11+
}
12+
13+
resource "aws_instance" "my_ec2" {
14+
ami = "ami-005fc0f236362e99f"
15+
instance_type = "t2.micro"
16+
17+
tags = {
18+
Name = "ExampleAppServerInstance"
19+
}
20+
}

01-AWS-EC2/outputs.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
output "instance_id" {
2+
description = "ID of the EC2 instance"
3+
value = aws_instance.my_ec2.id
4+
}
5+
6+
output "instance_public_ip" {
7+
description = "Public IP address of the EC2 instance"
8+
value = aws_instance.my_ec2.public_ip
9+
}

01-AWS-EC2/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
variable "instance_name" {
2+
description = "Value of the Name tag for the EC2 instance"
3+
type = string
4+
default = "ExampleAppServerInstance"
5+
}

02-AWS-Key-Pair/main.tf

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = "~> 4.16"
6+
}
7+
}
8+
9+
required_version = ">= 1.2.0"
10+
}
11+
12+
provider "aws" {
13+
region = "us-east-1"
14+
}
15+
16+
resource "aws_instance" "web" {
17+
ami = "ami-005fc0f236362e99f"
18+
instance_type = "t2.micro"
19+
security_groups = [aws_security_group.example.name]
20+
key_name = "TF_key"
21+
22+
tags = {
23+
Name = "web-server"
24+
}
25+
}
26+
27+
resource "aws_security_group" "example" {
28+
name = "launch-wizard-2"
29+
vpc_id = "vpc-061261ce2131c4b86"
30+
31+
ingress {
32+
from_port = 22
33+
to_port = 22
34+
protocol = "tcp"
35+
cidr_blocks = ["0.0.0.0/0"]
36+
}
37+
38+
ingress {
39+
from_port = 80
40+
to_port = 80
41+
protocol = "tcp"
42+
cidr_blocks = ["0.0.0.0/0"]
43+
}
44+
45+
ingress {
46+
from_port = 443
47+
to_port = 443
48+
protocol = "tcp"
49+
cidr_blocks = ["0.0.0.0/0"]
50+
}
51+
52+
egress {
53+
from_port = 0
54+
to_port = 0
55+
protocol = "-1"
56+
cidr_blocks = ["0.0.0.0/0"]
57+
}
58+
}
59+
60+
resource "aws_key_pair" "TF_key" {
61+
key_name = "TF_key"
62+
public_key = tls_private_key.rsa.public_key_openssh
63+
}
64+
65+
resource "tls_private_key" "rsa" {
66+
algorithm = "RSA"
67+
rsa_bits = 4096
68+
}
69+
70+
resource "local_file" "TF-key" {
71+
content = tls_private_key.rsa.private_key_pem
72+
filename = "tfkey"
73+
}
74+
75+
output "public_ip" {
76+
description = "Public IP of instance (or EIP)"
77+
value = aws_instance.web.public_ip
78+
}
79+
80+
output "private_ip" {
81+
description = "Private IP of instance"
82+
value = aws_instance.web.private_ip
83+
}

04-EC2-Jenkins/main.tf

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = "~> 4.16"
6+
}
7+
}
8+
9+
required_version = ">= 1.2.0"
10+
}
11+
12+
provider "aws" {
13+
region = "us-east-1"
14+
}
15+
16+
resource "aws_key_pair" "TF_key" {
17+
key_name = "TF_key"
18+
public_key = tls_private_key.rsa.public_key_openssh
19+
}
20+
21+
resource "tls_private_key" "rsa" {
22+
algorithm = "RSA"
23+
rsa_bits = 4096
24+
}
25+
26+
27+
resource "local_file" "TF-key" {
28+
content = tls_private_key.rsa.private_key_pem
29+
filename = "tfkey"
30+
}
31+
32+
resource "aws_instance" "Jenkins" {
33+
ami = "ami-0453ec754f44f9a4a"
34+
instance_type = "t2.micro"
35+
security_groups = [aws_security_group.Jenkins-sg.name]
36+
key_name = "TF_key"
37+
# user_data = file("./install.sh")
38+
39+
tags = {
40+
Name = "Jenkins-server"
41+
}
42+
43+
connection {
44+
type = "ssh"
45+
user = "ec2-user"
46+
private_key = tls_private_key.rsa.private_key_pem
47+
host = self.public_ip
48+
}
49+
50+
provisioner "remote-exec" {
51+
inline = [
52+
"sudo yum update -y",
53+
"sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo",
54+
"sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key",
55+
"sudo yum upgrade",
56+
"sudo yum install java-17-amazon-corretto -y",
57+
"sudo yum install jenkins -y",
58+
"sudo systemctl enable jenkins",
59+
"sudo systemctl start jenkins",
60+
"sleep 5",
61+
"sudo cat /var/lib/jenkins/secrets/initialAdminPassword",
62+
]
63+
}
64+
65+
}
66+
67+
resource "aws_security_group" "Jenkins-sg" {
68+
name = "launch-wizard-2"
69+
vpc_id = "vpc-061261ce2131c4b86"
70+
71+
ingress {
72+
from_port = 22
73+
to_port = 22
74+
protocol = "tcp"
75+
cidr_blocks = ["0.0.0.0/0"]
76+
}
77+
78+
# ingress {
79+
# from_port = 80
80+
# to_port = 80
81+
# protocol = "tcp"
82+
# cidr_blocks = ["0.0.0.0/0"]
83+
# }
84+
85+
ingress {
86+
from_port = 8080
87+
to_port = 8080
88+
protocol = "tcp"
89+
cidr_blocks = ["0.0.0.0/0"]
90+
}
91+
92+
egress {
93+
from_port = 0
94+
to_port = 0
95+
protocol = "-1"
96+
cidr_blocks = ["0.0.0.0/0"]
97+
}
98+
}
99+
100+
output "public_ip" {
101+
description = "Public IP of instance (or EIP)"
102+
value = aws_instance.Jenkins.public_ip
103+
}
104+
105+
output "private_ip" {
106+
description = "Private IP of instance"
107+
value = aws_instance.Jenkins.private_ip
108+
}

User-data/install.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
apt-get update
3+
apt-get install nginx -y
4+
echo "Nimendra" >/var/www/html/index.nginx-debian.html

User-data/main.tf

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = "~> 4.16"
6+
}
7+
}
8+
9+
required_version = ">= 1.2.0"
10+
}
11+
12+
provider "aws" {
13+
region = "us-east-1"
14+
}
15+
16+
resource "aws_instance" "web" {
17+
ami = "ami-005fc0f236362e99f"
18+
instance_type = "t2.micro"
19+
security_groups = [aws_security_group.example.name]
20+
key_name = "TF_key"
21+
user_data = file("./install.sh")
22+
23+
tags = {
24+
Name = "web-server"
25+
}
26+
}
27+
28+
resource "aws_security_group" "example" {
29+
name = "launch-wizard-2"
30+
vpc_id = "vpc-061261ce2131c4b86"
31+
32+
ingress {
33+
from_port = 22
34+
to_port = 22
35+
protocol = "tcp"
36+
cidr_blocks = ["0.0.0.0/0"]
37+
}
38+
39+
ingress {
40+
from_port = 80
41+
to_port = 80
42+
protocol = "tcp"
43+
cidr_blocks = ["0.0.0.0/0"]
44+
}
45+
46+
egress {
47+
from_port = 0
48+
to_port = 0
49+
protocol = "-1"
50+
cidr_blocks = ["0.0.0.0/0"]
51+
}
52+
}
53+
54+
resource "aws_key_pair" "TF_key" {
55+
key_name = "TF_key"
56+
public_key = tls_private_key.rsa.public_key_openssh
57+
}
58+
59+
resource "tls_private_key" "rsa" {
60+
algorithm = "RSA"
61+
rsa_bits = 4096
62+
}
63+
64+
resource "local_file" "TF-key" {
65+
content = tls_private_key.rsa.private_key_pem
66+
filename = "tfkey"
67+
}
68+
69+
output "public_ip" {
70+
description = "Public IP of instance (or EIP)"
71+
value = aws_instance.web.public_ip
72+
}
73+
74+
output "private_ip" {
75+
description = "Private IP of instance"
76+
value = aws_instance.web.private_ip
77+
}

0 commit comments

Comments
 (0)