ECS Task definitions can be tagged:
resource "aws_ecs_task_definition" "task" {
# ...
tags = {
ImATag = "yes indeed"
AnotherTag = "another one"
}
# ...
}
ECS services can be tagged as well and configured to propagate their tags to tasks:
resource "aws_ecs_service" "service_with_auto_scaling" {
# ...
tags = {
ImATag = "yes indeed"
AnotherTag = "another one"
}
propagate_tags = "SERVICE"
# ...
}
If you want the tasks from the ECS Task Definition to propagate to the ECS Tasks themselves, you can do this instead (thank you @williamfalconeruk for the additional info here!):
resource "aws_ecs_service" "service_with_auto_scaling" {
# ...
tags = {
ImATag = "yes indeed"
AnotherTag = "another one"
}
propagate_tags = "TASK_DEFINITION"
# ...
}
You need to log in as root and go to the ECS service settings and enable the new resource IDs for propagate_tags to work.