Continuous deployments with AWS ECS, Terraform and Jenkins (task definition revisions)
Here’s a quick and easy way to integrate continuously updated task definition deployments on AWS ECS with Terraform and Jenkins.
This approach assumes that you have setup an ECS cluster, service and task definition defined in Terraform and output various variables for use in the application’s build pipeline. An example of the infrastructure setup in Terraform might be as follows.
Build your application docker image
Assuming that we have a Terraform setup like the above, lets build and deploy our docker image to the ECR docker repository. I fetch the repository URL and some other arguments that are baked into the docker image via Terraform output commands that fetch values from the infrastructure remote state.
Create a task definition and update service
Now that we have built and pushed a docker image for this build we need to create a new task revision for the ECS service and tell it to run. You could simply use
latest as the image tag in your ECS task definition but I prefer explicit versioning. To do so we first use the
register-task-definition command and then