cloudposse / terraform-aws-ecs-container-definition

Terraform module to generate well-formed JSON documents (container definitions) that are passed to the aws_ecs_task_definition Terraform resource
https://cloudposse.com/accelerate
Apache License 2.0
340 stars 245 forks source link

Support initProcessEnabled on ECS Fargate #143

Closed oanhnn closed 3 years ago

oanhnn commented 3 years ago

Describe the Feature

Allow set parameter

linux_parameters = { initProcessEnabled = true }

Expected Behavior

Generate json with:

"linux_parameters": { "initProcessEnabled": true }

Use Case

When using ECS Fargate, some options like sharedMemorySize is not supported. If i set only initProcessEnabled then this module will throw error

│ Error: Invalid value for module argument
│
│   on main.tf line 564, in module "container_definition":
│  564:   linux_parameters = {
│  565:     initProcessEnabled = true
│  566:   }
│
│ The given value is not suitable for child module variable
│ "linux_parameters" defined at
│ .terraform/modules/container_definition/variables.tf:140,1-28: attributes
│ "capabilities", "devices", "maxSwap", "sharedMemorySize", "swappiness", and
│ "tmpfs" are required.

But if i set full options, aws_ecs_task_definition resource will throw error

aws_ecs_task_definition.app: Creating...
│
│ Error: ClientException: Fargate compatible task definitions do not support sharedMemorySize
│
│   with aws_ecs_task_definition.app,
│   on main.tf line 619, in resource "aws_ecs_task_definition" "app":
│  619: resource "aws_ecs_task_definition" "app" {
│

https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_LinuxParameters.html

gannino commented 3 years ago

Hello, I just encountered the same issue on EC2, probably setting it the way below should accept it? hope this helps

  linux_parameters = {
    "capabilities" = {
      add  = []
      drop = []
    }
    "devices" = []
    "initProcessEnabled" = true
    "maxSwap"            = null
    "sharedMemorySize"   = null
    "swappiness"         = null
    "tmpfs" = []
  }
nitrocode commented 3 years ago

In terraform, optional arguments are still not GA and so if we set an input variable as a defined object type, like we do with linux_parameters, then every key has to be defined unfortunately.

The only other option is to set an object type of simply map but then we don't get the plan time validation of correct inputs. The ideal would be both optional object arguments and plan time validation.

The solution @gannino pointed out is unsatisfyingly verbose but correct.