-
Notifications
You must be signed in to change notification settings - Fork 53
/
ecs.tf
60 lines (55 loc) · 1.41 KB
/
ecs.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
resource "aws_ecs_cluster" "cluster" {
name = local.ecs["cluster_name"]
capacity_providers = ["FARGATE"]
default_capacity_provider_strategy {
capacity_provider = "FARGATE"
weight = "100"
}
}
resource "aws_ecs_task_definition" "task" {
family = "service"
requires_compatibilities = [
"FARGATE",
]
execution_role_arn = aws_iam_role.fargate.arn
network_mode = "awsvpc"
cpu = 256
memory = 512
container_definitions = jsonencode([
{
name = local.container.name
image = local.container.image
essential = true
portMappings = [
for port in local.container.ports :
{
containerPort = port
hostPort = port
}
]
}
])
}
resource "aws_ecs_service" "service" {
name = local.ecs.service_name
cluster = aws_ecs_cluster.cluster.id
task_definition = aws_ecs_task_definition.task.arn
desired_count = 1
network_configuration {
subnets = [for s in data.aws_subnet.subnets : s.id]
assign_public_ip = true
}
load_balancer {
target_group_arn = aws_lb_target_group.group.arn
container_name = local.container.name
container_port = 80
}
deployment_controller {
type = "ECS"
}
capacity_provider_strategy {
base = 0
capacity_provider = "FARGATE"
weight = 100
}
}