-
Notifications
You must be signed in to change notification settings - Fork 3
/
ecs_service_fargate_httpbin.tf
96 lines (75 loc) · 2.15 KB
/
ecs_service_fargate_httpbin.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
data "template_file" "httpbin_fargate" {
template = file("templates/tasks/httpbin-fargate.json")
}
resource "aws_ecs_task_definition" "httpbin_fargate" {
count = var.enable_fargate_httpbin ? 1 : 0
container_definitions = data.template_file.httpbin_fargate.rendered
family = "httpbin-fargate"
requires_compatibilities = [
"FARGATE",
]
network_mode = "awsvpc"
cpu = 256
memory = 512
}
resource "aws_ecs_service" "httpbin_fargate" {
count = var.enable_fargate_httpbin ? 1 : 0
name = "httpbin-fargate"
cluster = aws_ecs_cluster.default.name
task_definition = aws_ecs_task_definition.httpbin_fargate[0].arn
desired_count = 1
launch_type = "FARGATE"
network_configuration {
security_groups = [
module.vpc.sg_allow_8080,
module.vpc.sg_allow_egress,
module.vpc.sg_allow_vpc,
]
subnets = [
module.vpc.subnet_private1,
]
}
depends_on = [aws_alb.httpbin_fargate]
load_balancer {
target_group_arn = aws_alb_target_group.httpbin_fargate[0].arn
container_name = "httpbin"
container_port = 8080
}
}
resource "aws_alb" "httpbin_fargate" {
count = var.enable_fargate_httpbin ? 1 : 0
name = "httpbin-fargate"
subnets = [
module.vpc.subnet_public1,
module.vpc.subnet_public2,
module.vpc.subnet_public3,
]
security_groups = [
module.vpc.sg_allow_egress,
module.vpc.sg_allow_80,
]
}
resource "aws_alb_listener" "httpbin_fargate" {
count = var.enable_fargate_httpbin ? 1 : 0
default_action {
target_group_arn = aws_alb_target_group.httpbin_fargate[0].arn
type = "forward"
}
load_balancer_arn = aws_alb.httpbin_fargate[0].arn
port = 80
}
resource "aws_alb_target_group" "httpbin_fargate" {
count = var.enable_fargate_httpbin ? 1 : 0
name = "httpbin-fargate"
vpc_id = module.vpc.vpc_id
port = 8080
protocol = "HTTP"
deregistration_delay = 5
target_type = "ip"
health_check {
healthy_threshold = 2
unhealthy_threshold = 10
interval = 5
timeout = 2
}
}