-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalb.tf
More file actions
111 lines (94 loc) · 3.33 KB
/
alb.tf
File metadata and controls
111 lines (94 loc) · 3.33 KB
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
// CREATE EXTERNAL ALB
resource "aws_alb" "external_alb" {
name = "${local.resource_prefix}-external-alb-${data.terraform_remote_state.vpc.aws_region_shortname}"
internal = false
security_groups = ["${aws_security_group.alb_security_group.id}"]
subnets = ["${data.terraform_remote_state.vpc.public_subnet_ids}"]
access_logs {
bucket = "${var.aws_account}-logs"
prefix = "${var.environment_name}/ecs/external-alb"
enabled = true
}
tags = "${merge(
local.common_tags,
map(
"Name", "${local.resource_prefix}-external-alb-${data.terraform_remote_state.vpc.aws_region_shortname}",
"name", "${local.resource_prefix}-external-alb-${data.terraform_remote_state.vpc.aws_region_shortname}"
)
)}"
}
// CREATE INTERNAL ALB
resource "aws_alb" "internal_alb" {
name = "${local.resource_prefix}-interal-alb-${data.terraform_remote_state.vpc.aws_region_shortname}"
internal = true
security_groups = ["${aws_security_group.alb_security_group.id}"]
subnets = ["${data.terraform_remote_state.vpc.private_subnet_ids}"]
access_logs {
bucket = "${var.aws_account}-logs"
prefix = "${var.environment_name}/ecs/internal-alb"
enabled = true
}
tags = "${merge(
local.common_tags,
map(
"Name", "${local.resource_prefix}-internal-alb-${data.terraform_remote_state.vpc.aws_region_shortname}",
"name", "${local.resource_prefix}-internal-alb-${data.terraform_remote_state.vpc.aws_region_shortname}"
)
)}"
}
// CREATE EXTERNAL ALB TARGET GROUP
resource "aws_alb_target_group" "external_alb_target_group" {
name = "${local.resource_prefix}-external-alb-tg-${data.terraform_remote_state.vpc.aws_region_shortname}"
port = 443
protocol = "HTTPS"
vpc_id = "${data.terraform_remote_state.vpc.vpc_id}"
health_check {
port = "traffic-port"
protocol = "HTTP"
matcher = 200
path = "/"
timeout = 2
interval = 5
healthy_threshold = 5
unhealthy_threshold = 2
}
}
// CREATE INTERNAL ALB TARGET GROUP
resource "aws_alb_target_group" "internal_alb_target_group" {
name = "${local.resource_prefix}-internal-alb-tg-${data.terraform_remote_state.vpc.aws_region_shortname}"
port = 443
protocol = "HTTPS"
vpc_id = "${data.terraform_remote_state.vpc.vpc_id}"
health_check {
port = "traffic-port"
protocol = "HTTP"
matcher = 200
path = "/"
timeout = 2
interval = 5
healthy_threshold = 5
unhealthy_threshold = 2
}
}
// CREATE EXTERNAL ALB LISTENER
resource "aws_alb_listener" "external_alb_listener" {
load_balancer_arn = "${aws_alb.external_alb.arn}"
port = "443"
protocol = "HTTPS"
certificate_arn = "${data.terraform_remote_state.account.ssl_arn}"
default_action {
target_group_arn = "${aws_alb_target_group.external_alb_target_group.arn}"
type = "forward"
}
}
// CREATE INTERNAL ALB LISTENER
resource "aws_alb_listener" "internal_alb_listener" {
load_balancer_arn = "${aws_alb.internal_alb.arn}"
port = "443"
protocol = "HTTPS"
certificate_arn = "${data.terraform_remote_state.account.ssl_arn}"
default_action {
target_group_arn = "${aws_alb_target_group.internal_alb_target_group.arn}"
type = "forward"
}
}