forked from rahulwagh/terraform-jenkins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
77 lines (65 loc) · 1.67 KB
/
main.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
variable "ec2_sg_name" {}
variable "vpc_id" {}
variable "ec2_jenkins_sg_name" {}
output "sg_ec2_sg_ssh_http_id" {
value = aws_security_group.ec2_sg_ssh_http.id
}
output "sg_ec2_jenkins_port_8080" {
value = aws_security_group.ec2_jenkins_port_8080.id
}
resource "aws_security_group" "ec2_sg_ssh_http" {
name = var.ec2_sg_name
description = "Enable the Port 22(SSH) & Port 80(http)"
vpc_id = var.vpc_id
# ssh for terraform remote exec
ingress {
description = "Allow remote SSH from anywhere"
cidr_blocks = ["0.0.0.0/0"]
from_port = 22
to_port = 22
protocol = "tcp"
}
# enable http
ingress {
description = "Allow HTTP request from anywhere"
cidr_blocks = ["0.0.0.0/0"]
from_port = 80
to_port = 80
protocol = "tcp"
}
# enable http
ingress {
description = "Allow HTTP request from anywhere"
cidr_blocks = ["0.0.0.0/0"]
from_port = 443
to_port = 443
protocol = "tcp"
}
#Outgoing request
egress {
description = "Allow outgoing request"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "Security Groups to allow SSH(22) and HTTP(80)"
}
}
resource "aws_security_group" "ec2_jenkins_port_8080" {
name = var.ec2_jenkins_sg_name
description = "Enable the Port 8080 for jenkins"
vpc_id = var.vpc_id
# ssh for terraform remote exec
ingress {
description = "Allow 8080 port to access jenkins"
cidr_blocks = ["0.0.0.0/0"]
from_port = 8080
to_port = 8080
protocol = "tcp"
}
tags = {
Name = "Security Groups to allow SSH(22) and HTTP(80)"
}
}