-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathecs-task-definition.tf
71 lines (59 loc) · 2.08 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
68
69
70
71
resource "aws_ecs_task_definition" "default" {
count = var.image != "" ? 1 : 0
family = "${var.cluster_name}-${var.name}"
execution_role_arn = var.task_role_arn != null ? var.task_role_arn : aws_iam_role.ecs_task[0].arn
task_role_arn = var.task_role_arn != null ? var.task_role_arn : aws_iam_role.ecs_task[0].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
command = var.command
readonlyRootFilesystem = var.readonlyrootfilesystem
portMappings = [
{
containerPort = var.container_port
}
]
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]
}]
secrets = [for k, v in var.ssm_variables : { name : k, valueFrom : v }]
environment = [for k, v in var.static_variables : { name : k, value : v }]
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]
replace_triggered_by = [aws_lb_target_group.green]
}
tags = merge(var.tags, { "terraform" = "true" }, )
}