Skip to content

Commit b86e2f4

Browse files
committed
Tweak
1 parent 5976c5a commit b86e2f4

File tree

1 file changed

+36
-23
lines changed
  • operations/deployment/terraform/modules/aws/ecs

1 file changed

+36
-23
lines changed

operations/deployment/terraform/modules/aws/ecs/aws_ecs.tf

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@ resource "aws_ecs_task_definition" "ecs_task" {
3434
execution_role_arn = local.ecsTaskExecutionRole
3535

3636
container_definitions = sensitive(jsonencode(
37-
[
37+
var.aws_ecs_cloudwatch_enable && var.aws_ecs_cloudwatch_log_driver == "awsfirelens" ? [
3838
{
3939
"name": var.aws_ecs_task_name != "" ? local.aws_ecs_task_name[count.index] : "${local.aws_ecs_task_name[count.index]}${count.index}",
4040
"image": local.aws_ecs_app_image[count.index],
4141
"cpu": local.aws_ecs_container_cpu[count.index],
4242
"memory": local.aws_ecs_container_mem[count.index],
43+
"essential": true,
4344
"portMappings": [
4445
{
4546
"containerPort": tonumber(local.aws_ecs_container_port[count.index]),
@@ -48,35 +49,47 @@ resource "aws_ecs_task_definition" "ecs_task" {
4849
}
4950
],
5051
"environment": local.env_repo_vars,
51-
"logConfiguration": (
52-
var.aws_ecs_cloudwatch_enable && var.aws_ecs_cloudwatch_log_driver == "awslogs" ?
53-
{
54-
"logDriver": "awslogs",
55-
"options": {
56-
"awslogs-create-group": "true",
57-
"awslogs-region": var.aws_region_current_name,
58-
"awslogs-group": var.aws_ecs_cloudwatch_lg_name,
59-
"awslogs-stream-prefix": aws_ecs_cluster.cluster.name
60-
}
61-
} :
62-
var.aws_ecs_cloudwatch_enable && var.aws_ecs_cloudwatch_log_driver == "awsfirelens" ?
63-
{
64-
"logDriver": "awsfirelens",
65-
"options": merge(
66-
{ "Name": var.aws_ecs_firelens_output_type },
67-
jsondecode(var.aws_ecs_firelens_output_options)
68-
)
69-
} : null
70-
)
52+
"logConfiguration": {
53+
"logDriver": "awsfirelens",
54+
"options": merge(
55+
{ "Name": var.aws_ecs_firelens_output_type },
56+
jsondecode(var.aws_ecs_firelens_output_options)
57+
)
58+
}
7159
},
72-
var.aws_ecs_cloudwatch_enable && var.aws_ecs_cloudwatch_log_driver == "awsfirelens" ? {
60+
{
7361
"name": "log_router",
7462
"image": "public.ecr.aws/aws-observability/aws-for-fluent-bit:latest",
7563
"essential": false,
7664
"firelensConfiguration": {
7765
"type": "fluentbit"
7866
}
79-
} : null
67+
}
68+
] : [
69+
{
70+
"name": var.aws_ecs_task_name != "" ? local.aws_ecs_task_name[count.index] : "${local.aws_ecs_task_name[count.index]}${count.index}",
71+
"image": local.aws_ecs_app_image[count.index],
72+
"cpu": local.aws_ecs_container_cpu[count.index],
73+
"memory": local.aws_ecs_container_mem[count.index],
74+
"essential": true,
75+
"portMappings": [
76+
{
77+
"containerPort": tonumber(local.aws_ecs_container_port[count.index]),
78+
"hostPort": tonumber(local.aws_ecs_container_port[count.index]),
79+
"protocol": "tcp"
80+
}
81+
],
82+
"environment": local.env_repo_vars,
83+
"logConfiguration": var.aws_ecs_cloudwatch_enable && var.aws_ecs_cloudwatch_log_driver == "awslogs" ? {
84+
"logDriver": "awslogs",
85+
"options": {
86+
"awslogs-create-group": "true",
87+
"awslogs-region": var.aws_region_current_name,
88+
"awslogs-group": var.aws_ecs_cloudwatch_lg_name,
89+
"awslogs-stream-prefix": aws_ecs_cluster.cluster.name
90+
}
91+
} : null
92+
}
8093
]
8194
))
8295
}

0 commit comments

Comments
 (0)