-
Notifications
You must be signed in to change notification settings - Fork 0
/
04-alb.tf
136 lines (118 loc) · 4.29 KB
/
04-alb.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
#ALB
resource "aws_alb" "jenkins" {
name = "${var.account_shorthand}-${var.environment}-${var.service}"
internal = false
security_groups = ["${aws_security_group.jenkins_alb.id}"]
subnets = ["${element(module.vpc.public_subnets, 0)}",
"${element(module.vpc.public_subnets, 1)}",
"${element(module.vpc.public_subnets, 2)}"]
enable_deletion_protection = true
tags {
Account_shorthand = "${var.account_shorthand}"
Name = "${var.account_shorthand}_${var.environment}_${var.service}"
Environment = "${var.environment}"
Identifier = "${var.account_shorthand}_${var.environment}_${var.service}"
ManagedBy = "terraform"
Service = "${var.service}"
}
}
resource "aws_alb_listener" "jenkins" {
load_balancer_arn = "${aws_alb.jenkins.arn}"
port = "443"
protocol = "HTTPS"
ssl_policy = "ELBSecurityPolicy-2016-08"
certificate_arn = "${aws_acm_certificate_validation.jenkins_cert_validation.certificate_arn}"
default_action {
target_group_arn = "${aws_alb_target_group.jenkins_http.arn}"
type = "forward"
}
}
resource "aws_acm_certificate" "jenkins" {
domain_name = "${var.alb_ssl_cert}"
validation_method = "DNS"
}
data "aws_route53_zone" "domain_zone" {
name = "${var.domain_hosted_zone}"
private_zone = false
}
resource "aws_route53_record" "jenkins_cert_validation" {
name = "${aws_acm_certificate.jenkins.domain_validation_options.0.resource_record_name}"
type = "${aws_acm_certificate.jenkins.domain_validation_options.0.resource_record_type}"
zone_id = "${data.aws_route53_zone.domain_zone.id}"
records = ["${aws_acm_certificate.jenkins.domain_validation_options.0.resource_record_value}"]
ttl = 300
}
resource "aws_acm_certificate_validation" "jenkins_cert_validation" {
certificate_arn = "${aws_acm_certificate.jenkins.arn}"
validation_record_fqdns = ["${aws_route53_record.jenkins_cert_validation.fqdn}"]
}
###TG
resource "aws_alb_target_group" "jenkins_http" {
name = "${var.account_shorthand}-${var.environment}-${var.service}"
port = "8080"
protocol = "HTTP"
vpc_id = "${module.vpc.vpc_id}"
deregistration_delay = "60"
stickiness {
enabled = false
type = "lb_cookie"
cookie_duration = "86400"
}
health_check {
interval = "5"
path = "/"
protocol = "HTTP"
timeout = "2"
healthy_threshold = "2"
unhealthy_threshold = "2"
matcher = "200"
}
tags {
Account_shorthand = "${var.account_shorthand}"
Name = "${var.account_shorthand}_${var.environment}_${var.service}"
Environment = "${var.environment}"
Identifier = "${var.account_shorthand}_${var.environment}_${var.service}"
ManagedBy = "terraform"
Service = "${var.service}"
Owner = ""
Project = ""
}
}
###SG
# Security groups
resource "aws_security_group" "jenkins_alb" {
name = "${var.account_shorthand}_${var.environment}_${var.service}_alb"
description = "Allow access to ${var.account_shorthand}_${var.environment}_${var.service} instance(s)"
vpc_id = "${module.vpc.vpc_id}"
lifecycle {
ignore_changes = [
"description",
"ami"]
}
tags {
Account_shorthand = "${var.account_shorthand}"
Environment = "${var.environment}"
Name = "${var.account_shorthand}_${var.environment}_${var.service}_alb"
Identifier = "${var.account_shorthand}_${var.environment}_${var.service}"
ManagedBy = "terraform"
Service = "${var.service}"
Owner = ""
Project = ""
}
}
resource "aws_security_group_rule" "jenkins_https" {
security_group_id = "${aws_security_group.jenkins_alb.id}"
from_port = 443
to_port = 443
protocol = "tcp"
type = "ingress"
cidr_blocks = ["0.0.0.0/0"]
}
resource "aws_security_group_rule" "jenkins_egress_alb" {
security_group_id = "${aws_security_group.jenkins_alb.id}"
from_port = 0
to_port = 0
protocol = "-1"
type = "egress"
cidr_blocks = ["0.0.0.0/0"]
}