title: How to keep the last X ECS task definitions active?
body: <p>I have the following Terraform code to update a service with a new task definition:</p>
  
  <pre><code>resource "aws_ecs_task_definition" "app_definition" {
    family = "my-family"
  
    container_definitions = "${data.template_file.task_definition.rendered}"
    network_mode          = "bridge"
  }
  
  resource "aws_ecs_service" "app_service" {
    name            = "my-service"
    cluster         = "my-cluster"
    task_definition = "${aws_ecs_task_definition.app_definition.arn}"
    desired_count   = "1"
    iam_role        = "my-iam-role"
  }
  </code></pre>
  
  <p>When updating my service, the last revision of my task definition becomes inactive. As a result, I can not select it when trying to manually roll back to a previous revision in the ECS console:</p>
  
  <pre><code>Error: No active task definition found
  </code></pre>
  
  <p>Ideally, I want to keep the last X revisions active so I can always manually roll back via the console if something goes wrong.</p>
  
  <p>How can I achieve that?</p>