-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathalb.tf
63 lines (53 loc) · 1.43 KB
/
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
resource "aws_security_group" "ecs_alb" {
description = "Balancer for ${var.app_name}"
vpc_id = "${var.vpc}"
name = "${var.app_name}-alb-sg"
ingress {
protocol = "tcp"
from_port = "${var.app_port}"
to_port = "${var.app_port}"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_alb" "main" {
name = "${var.app_name}"
subnets = "${var.subnets}"
security_groups = ["${aws_security_group.ecs_alb.id}"]
}
resource "aws_alb_target_group" "main" {
name = "${var.app_name}"
port = "${var.app_port}"
protocol = "HTTP"
vpc_id = "${var.vpc}"
depends_on = [
"aws_alb.main"
]
}
resource "aws_alb_listener" "https" {
count = "${var.https ? 1 : 0}"
load_balancer_arn = "${aws_alb.main.id}"
port = "443"
protocol = "HTTPS"
ssl_policy = "${var.app_ssl_policy}"
certificate_arn = "${var.app_certificate_arn}"
default_action {
target_group_arn = "${aws_alb_target_group.main.id}"
type = "forward"
}
}
resource "aws_alb_listener" "http" {
count = "${var.https ? 0 : 1}"
load_balancer_arn = "${aws_alb.main.id}"
port = "80"
protocol = "HTTP"
default_action {
target_group_arn = "${aws_alb_target_group.main.id}"
type = "forward"
}
}