infrablocks / terraform-aws-ecs-service

Terraform module for deploying a service to an existing ECS cluster in AWS
MIT License
36 stars 20 forks source link

[Feature] Support service_use_latest_task_definition to use the latest task definition #81

Closed jeroenhabets closed 1 year ago

jeroenhabets commented 1 year ago

Because of an upcoming .Net8 upgrade we're changing our container port to unprivileged 8080 for better security [1].

For this we've updated our task definitions but when recreating the service, the terraform-aws-ecs-service module for some reason for us always uses the first created task definition it finds and not the latest.

Some users may actually want the terraform-aws-ecs-service module to only use the task definition created by the module so we suggest to introduce a service_use_latest_task_definition bool parameter.

If use_latest_task_definition is provided use the latest revision of the task definition If not provided or false (default), keep the current behaviour of using the task definition from task_definition.tf

Thanks to @tobyclemson's suggestion trivial to implement using ecs_task_definition.arn_without_revision by changing service.tf#L4 to

task_definition = var.service_use_latest_task_definition ? aws_ecs_task_definition.service.arn_without_revision : aws_ecs_task_definition.service.arn

[1] https://learn.microsoft.com/en-us/dotnet/core/compatibility/containers/8.0/aspnet-port