telia-oss / terraform-aws-ecs-fargate

Terraform module which creates Fargate ECS resources on AWS.
https://registry.terraform.io/modules/telia-oss/ecs-fargate/aws
MIT License
82 stars 75 forks source link

Variable to configure container_definitions cpu and memory #89

Open Anthony-Michel opened 1 year ago

Anthony-Michel commented 1 year ago

Feature request

How can we improve the module? I'm running an ASP.Net in ECS and as highlighted in this article https://aws.amazon.com/blogs/developer/configuring-net-garbage-collection-for-amazon-ecs-and-aws-lambda/ i need to set the container CPU and memory size to avoid OOM. hence i would need to either be able to inject those cpu and memory values to the container_definiton container_definitions = jsonencode([ { name = "first" image = "service-first" cpu = 10 memory = 512 essential = true portMappings = [ { containerPort = 80 hostPort = 80 } ] }

or at least have those values set by default with the values configured at the task_definition level Code to be updated for default being same as task_defintion :

container_definition = merge({
"name"             = var.container_name != "" ? var.container_name : var.name_prefix
"image"            = var.task_container_image,
"essential"        = true
"cpu"                = var.task_definition_cpu
"memory"        = var.task_definition_memory
"portMappings"     = local.task_container_port_mappings
"stopTimeout"      = var.stop_timeout
"command"          = var.task_container_command
"environment"      = local.task_container_environment
"environmentFiles" = var.task_container_environment_file
"MountPoints"      = local.task_container_mount_points
"logConfiguration" = {
  "logDriver" = "awslogs"
  "options"   = local.log_configuration_options
}
"privileged" : var.privileged
"readonlyRootFilesystem" : var.readonlyRootFilesystem
}, local.task_container_secrets, local.repository_credentials)

And solution with new specific variable :

container_definition = merge({
"name"             = var.container_name != "" ? var.container_name : var.name_prefix
"image"            = var.task_container_image,
"essential"        = true
"cpu"                = var.container_cpu
"memory"        = var.container_memory
"portMappings"     = local.task_container_port_mappings
"stopTimeout"      = var.stop_timeout
"command"          = var.task_container_command
"environment"      = local.task_container_environment
"environmentFiles" = var.task_container_environment_file
"MountPoints"      = local.task_container_mount_points
"logConfiguration" = {
  "logDriver" = "awslogs"
  "options"   = local.log_configuration_options
}
"privileged" : var.privileged
"readonlyRootFilesystem" : var.readonlyRootFilesystem
}, local.task_container_secrets, local.repository_credentials)