-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathecs-task-definition.tf
67 lines (57 loc) · 1.68 KB
/
ecs-task-definition.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
locals {
port_mappings = [
for port in var.ports : {
hostPort = port.port
protocol = port.protocol
containerPort = port.port
}
]
}
resource "aws_ecs_task_definition" "default" {
family = "${var.cluster_name}-${var.name}"
execution_role_arn = var.task_role_arn
task_role_arn = var.task_role_arn
requires_compatibilities = [var.launch_type]
network_mode = var.launch_type == "FARGATE" ? "awsvpc" : var.network_mode
cpu = var.launch_type == "FARGATE" ? var.cpu : null
memory = var.launch_type == "FARGATE" ? var.memory : null
container_definitions = jsonencode([
{
name = var.name
image = var.image
cpu = var.cpu
memory = var.memory
essential = true
portMappings = local.port_mappings
logConfiguration = {
logDriver = "awslogs"
options = {
awslogs-group = aws_cloudwatch_log_group.default.name
awslogs-region = data.aws_region.current.name
awslogs-stream-prefix = "app"
}
}
mountPoints = length(var.efs_mapping) == 0 ? null : [{
sourceVolume = "efs-${keys(var.efs_mapping)[0]}"
containerPath = values(var.efs_mapping)[0]
}]
ulimits = var.ulimits
}
])
dynamic "volume" {
for_each = var.efs_mapping
content {
name = "efs-${volume.key}"
efs_volume_configuration {
file_system_id = volume.key
transit_encryption = "ENABLED"
authorization_config {
access_point_id = aws_efs_access_point.default[volume.key].id
}
}
}
}
lifecycle {
ignore_changes = [container_definitions]
}
}