|
1 | 1 | resource "aws_ecs_task_definition" "task" { |
2 | 2 | family = "${var.cluster_name}-${var.service_name}" |
3 | | - container_definitions = jsonencode([ |
| 3 | + container_definitions = jsonencode([for s in concat([ |
4 | 4 | { |
5 | 5 | name = var.service_name |
6 | 6 | image = var.image |
7 | 7 | cpu = var.cpu |
8 | 8 | essential = var.essential |
9 | 9 | memory = var.memory |
10 | 10 | memoryReservation = var.memory_reservation |
11 | | - portMappings = local.balanced ? coalescelist(var.port_mappings, local.defaultPortMappings) : [] |
12 | 11 | mountPoints = [] |
13 | | - logConfiguration = local.log_configuration |
14 | | - environment = [for k in sort(keys(var.environment)) : { "name" : k, "value" : var.environment[k] }] |
15 | 12 | volumesFrom = [] |
16 | 13 | } |
17 | | - ]) |
| 14 | + ], var.additional_container_definitions) : merge(s, { |
| 15 | + environment = [for k in sort(keys(var.environment)) : { "name" : k, "value" : var.environment[k] }] |
| 16 | + # leverage the new terraform syntax and override the awslogs-stream-prefix |
| 17 | + logConfiguration = merge(local.log_configuration, |
| 18 | + local.log_configuration["logDriver"] == "awslogs" && local.log_configuration["options"] != null ? { |
| 19 | + options = merge(local.log_configuration["options"], { "awslogs-stream-prefix" = s.name }) |
| 20 | + } : {} |
| 21 | + ) |
| 22 | + # load balancer the local.load_balancer_container_name |
| 23 | + portMappings = local.balanced && local.load_balancer_container_name == s.name ? coalescelist(var.port_mappings, local.defaultPortMappings) : [] |
| 24 | + })]) |
18 | 25 |
|
19 | 26 | task_role_arn = var.task_role_arn |
20 | 27 |
|
@@ -44,7 +51,7 @@ resource "aws_ecs_service" "service" { |
44 | 51 |
|
45 | 52 | content { |
46 | 53 | target_group_arn = load_balancer.value |
47 | | - container_name = var.service_name |
| 54 | + container_name = local.load_balancer_container_name |
48 | 55 | container_port = var.container_port |
49 | 56 | } |
50 | 57 | } |
|
0 commit comments