-
Notifications
You must be signed in to change notification settings - Fork 0
/
alb.tf
74 lines (62 loc) · 2.01 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
64
65
66
67
68
69
70
71
72
73
74
# To expose the container to the internet, we will be using an Application Load-Balancer (ALB).
# To be able to route traffic to our containers, we create a target group and regsiter the containers with it.
# We then have the ALB route traffic to the target group.
# We require the following components for it:
# 1. A target group
# 2. An ALB
# 3. A security group for the ALB to define how it may be accessed.
resource "aws_security_group" "alb" {
name = "alb-${var.alb_name}"
description = "ALB Security Group."
vpc_id = "${module.vpc.vpc_id}"
tags = {
Name = "alb-${var.alb_name}"
}
}
resource "aws_security_group_rule" "alb_allow_http" {
type = "ingress"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = "${aws_security_group.alb.id}"
}
resource "aws_security_group_rule" "alb_allow_egress" {
type = "egress"
from_port = 0
to_port = 65535
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = "${aws_security_group.alb.id}"
}
resource "aws_alb_target_group" "webinar_service_target_group" {
name = "${var.container_name}-target-group"
port = "${var.container_port}"
protocol = "HTTP"
vpc_id = "${module.vpc.vpc_id}"
target_type = "ip"
deregistration_delay = 10
health_check {
interval = 5
timeout = 4
healthy_threshold = 2
}
lifecycle {
create_before_destroy = true
}
depends_on = ["aws_alb.webinar_alb"]
}
resource "aws_alb" "webinar_alb" {
name = "${var.alb_name}"
subnets = "${module.vpc.public_subnets}"
security_groups = ["${aws_security_group.alb.id}"]
}
resource "aws_alb_listener" "webinar_app" {
load_balancer_arn = "${aws_alb.webinar_alb.arn}"
port = "80"
protocol = "HTTP"
default_action {
target_group_arn = "${aws_alb_target_group.webinar_service_target_group.arn}"
type = "forward"
}
}