This repository has been archived by the owner on Jul 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
jenkins-public.tf
204 lines (170 loc) · 6.9 KB
/
jenkins-public.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
data "aws_iam_policy_document" "jenkins-assume-role-policy" {
statement {
effect = "Allow"
actions = [
"sts:AssumeRole",
]
principals {
type = "Service"
identifiers = [
"ec2.amazonaws.com"
]
}
}
}
resource "aws_iam_role" "jenkins-role" {
name = "JenkinsRole"
assume_role_policy = "${data.aws_iam_policy_document.jenkins-assume-role-policy.json}"
}
resource "aws_iam_role_policy_attachment" "jenkins-access-policy" {
role = "${aws_iam_role.jenkins-role.name}"
policy_arn = "${lookup(var.unmanaged_role_arns, "mozdef-logging")}"
}
resource "aws_iam_instance_profile" "jenkins-profile" {
name = "jenkins-profile"
roles = ["${aws_iam_role.jenkins-role.name}"]
}
resource "aws_security_group" "jenkins-public-ec2-sg" {
name = "jenkins-public-ec2-sg"
description = "jenkins-public SG"
vpc_id = "${aws_vpc.apps-shared-vpc.id}"
}
resource "aws_security_group_rule" "jenkins-public-ec2-sg-allowsharedssh" {
type = "ingress"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["${aws_vpc.apps-shared-vpc.cidr_block}"]
security_group_id = "${aws_security_group.jenkins-public-ec2-sg.id}"
}
resource "aws_security_group_rule" "jenkins-public-ec2-sg-allowhttpfromjenkins-public-elb" {
type = "ingress"
from_port = 8080
to_port = 8080
protocol = "tcp"
source_security_group_id = "${aws_security_group.jenkins-public-elb-sg.id}"
security_group_id = "${aws_security_group.jenkins-public-ec2-sg.id}"
}
resource "aws_security_group_rule" "jenkins-public-ec2-sg-allowmesosframework" {
type = "ingress"
from_port = 10000
to_port = 65535
protocol = "tcp"
source_security_group_id = "${module.mesos-cluster-staging.mesos-cluster-master-sg-id}"
security_group_id = "${aws_security_group.jenkins-public-ec2-sg.id}"
}
resource "aws_security_group_rule" "jenkins-public-ec2-sg-allowprodmesosframework" {
type = "ingress"
from_port = 10000
to_port = 65535
protocol = "tcp"
source_security_group_id = "${module.mesos-cluster-production.mesos-cluster-master-sg-id}"
security_group_id = "${aws_security_group.jenkins-public-ec2-sg.id}"
}
resource "aws_security_group_rule" "jenkins-public-ec2-sg-allowjnlpfromslave" {
type = "ingress"
from_port = 50000
to_port = 50000
protocol = "tcp"
source_security_group_id = "${module.mesos-cluster-staging.mesos-cluster-slave-sg-id}"
security_group_id = "${aws_security_group.jenkins-public-ec2-sg.id}"
}
resource "aws_security_group_rule" "jenkins-public-ec2-sg-allowjnlpfromprodslave" {
type = "ingress"
from_port = 50000
to_port = 50000
protocol = "tcp"
source_security_group_id = "${module.mesos-cluster-production.mesos-cluster-slave-sg-id}"
security_group_id = "${aws_security_group.jenkins-public-ec2-sg.id}"
}
resource "aws_security_group_rule" "jenkins-public-ec2-sg-allowhttpfromall" {
type = "ingress"
from_port = 8080
to_port = 8080
protocol = "tcp"
cidr_blocks = [
"${aws_vpc.apps-shared-vpc.cidr_block}",
"${aws_vpc.apps-staging-vpc.cidr_block}",
"${aws_vpc.apps-production-vpc.cidr_block}"
]
security_group_id = "${aws_security_group.jenkins-public-ec2-sg.id}"
}
resource "aws_security_group_rule" "jenkins-public-ec2-sg-allowallegress" {
type = "egress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = "${aws_security_group.jenkins-public-ec2-sg.id}"
}
resource "aws_instance" "jenkins-public-ec2" {
ami = "${lookup(var.aws_amis, var.aws_region)}"
instance_type = "t2.medium"
disable_api_termination = true
key_name = "ansible"
vpc_security_group_ids = ["${aws_security_group.jenkins-public-ec2-sg.id}"]
iam_instance_profile = "${aws_iam_instance_profile.jenkins-profile.name}"
subnet_id = "${aws_subnet.apps-shared-1c.id}"
root_block_device {
volume_type = "gp2"
volume_size = 100
}
tags {
Name = "jenkins-public"
app = "jenkins"
env = "shared"
project = "partinfra"
}
}
resource "aws_security_group" "jenkins-public-elb-sg" {
name = "jenkins-public-elb-sg"
description = "jenkins-public ELB SG"
vpc_id = "${aws_vpc.apps-shared-vpc.id}"
}
resource "aws_security_group_rule" "jenkins-public-elb-sg-allowhttps" {
type = "ingress"
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = "${aws_security_group.jenkins-public-elb-sg.id}"
}
resource "aws_security_group_rule" "jenkins-public-elb-sg-allowall" {
type = "egress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = "${aws_security_group.jenkins-public-elb-sg.id}"
}
resource "aws_elb" "jenkins-public-elb" {
name = "jenkins-public-elb"
security_groups = ["${aws_security_group.jenkins-public-elb-sg.id}"]
subnets = ["${aws_subnet.apps-shared-1c.id}"]
internal = false
listener {
instance_port = 8081
instance_protocol = "http"
lb_port = 443
lb_protocol = "https"
ssl_certificate_id = "${lookup(var.ssl_certificates, "mesos-elb-${var.aws_region}")}"
}
health_check {
healthy_threshold = 2
unhealthy_threshold = 2
timeout = 3
target = "TCP:8080"
interval = 30
}
instances = ["${aws_instance.jenkins-public-ec2.id}"]
cross_zone_load_balancing = true
idle_timeout = 400
connection_draining = true
connection_draining_timeout = 400
tags {
Name = "jenkins-public-elb"
app = "jenkins"
env = "shared"
project = "partinfra"
}
}