forked from dhaiducek/ocp311_tf_aws
-
Notifications
You must be signed in to change notification settings - Fork 1
/
elb.tf
111 lines (104 loc) · 3.13 KB
/
elb.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
#~~~~~~~~~~~~~~~~~~~~~~~~~~~#
# PUBLIC LOAD BALANCER #
#~~~~~~~~~~~~~~~~~~~~~~~~~~~#
# Create Master Public Elastic Load Balancer
resource "aws_lb" "master_elb" {
name = "${local.cluster_id}-master"
internal = false
load_balancer_type = "network"
subnets = [aws_subnet.public_subnet.id]
enable_cross_zone_load_balancing = true
tags = merge(
local.common_tags,
tomap({
"Name" = "${local.cluster_id}-master-elb"
})
)
}
# Create Master Load Balancer listener for port 8443
resource "aws_lb_listener" "listener_master_elb" {
load_balancer_arn = aws_lb.master_elb.arn
port = 8443
protocol = "TCP"
default_action {
target_group_arn = aws_lb_target_group.group_master_elb.arn
type = "forward"
}
}
# Create Master Load Balancer listener for port 80
resource "aws_lb_listener" "listener_http_elb" {
load_balancer_arn = aws_lb.master_elb.arn
port = 80
protocol = "TCP"
default_action {
target_group_arn = aws_lb_target_group.group_http_elb.arn
type = "forward"
}
}
# Create Master Load Balancer listener for port 443
resource "aws_lb_listener" "listener_https_elb" {
load_balancer_arn = aws_lb.master_elb.arn
port = 443
protocol = "TCP"
default_action {
target_group_arn = aws_lb_target_group.group_https_elb.arn
type = "forward"
}
}
# Create Master target group for port 8443
resource "aws_lb_target_group" "group_master_elb" {
name = "${local.cluster_id}-master-elb-group"
port = 8443
protocol = "TCP"
vpc_id = aws_vpc.ocp311.id
tags = merge(
local.common_tags,
tomap({
"Name" = "${local.cluster_id}-master-elb-group"
})
)
}
# Create Master target group for port 80
resource "aws_lb_target_group" "group_http_elb" {
name = "${local.cluster_id}-http-group"
port = 80
protocol = "TCP"
vpc_id = aws_vpc.ocp311.id
tags = merge(
local.common_tags,
tomap({
"Name" = "${local.cluster_id}-http-group"
})
)
}
# Create Master target group for port 443
resource "aws_lb_target_group" "group_https_elb" {
name = "${local.cluster_id}-https-group"
port = 443
protocol = "TCP"
vpc_id = aws_vpc.ocp311.id
tags = merge(
local.common_tags,
tomap({
"Name" = "${local.cluster_id}-https-group"
})
)
}
# Attach Master group to EC2 instance
resource "aws_lb_target_group_attachment" "attachment_master_elb" {
target_group_arn = aws_lb_target_group.group_master_elb.arn
target_id = aws_instance.master.id
port = 8443
}
# Attach Master group to EC2 instance
resource "aws_lb_target_group_attachment" "attachment_master_http_elb" {
target_group_arn = aws_lb_target_group.group_http_elb.arn
target_id = aws_instance.master.id
port = 80
}
# Attach Master group to EC2 instance
resource "aws_lb_target_group_attachment" "attachment_master_https_elb" {
target_group_arn = aws_lb_target_group.group_https_elb.arn
target_id = aws_instance.master.id
port = 443
}