title: Replace ECS container instances in terraform setup
body: <p>We have a terraform deployment that creates an auto-scaling group for EC2 instances that we use as docker hosts in an ECS cluster. On the cluster there are tasks running. Replacing the tasks (e.g. with a newer version) works fine (by creating a new task definition revision and updating the service -- AWS will perform a rolling update). However, how can I easily replace the EC2 host instances with newer ones without any downtime?</p>
  
  <p>I'd like to do this to e.g. have a change to the ASG launch configuration take effect, for example switching to a different EC2 instance type.</p>
  
  <p>I've tried a few things, here's what I think gets closest to what I want:</p>
  
  <ol>
  <li>Drain one instance. The tasks will be distributed to the remaining instances.</li>
  <li>Once no tasks are running in that instance anymore, terminate it.</li>
  <li>Wait for the ASG to spin up a new instance.</li>
  <li>Repeat steps 1 to 3 until all instances are new.</li>
  </ol>
  
  <p>This works almost. The problem is that:</p>
  
  <ol>
  <li>It's manual and therefore error prone.</li>
  <li>After this process one of the instances (the last one that was spun up) is running 0 (zero) tasks.</li>
  </ol>
  
  <p>Is there a better, automated way of doing this? Also, is there a way to re-distribute the tasks in an ECS cluster (without creating a new task revision)?</p>