Continuous Deployment and Delivery on ECS Fargate with Terraform

Hey all,

My goal is simple. Commit a change to the application and have it running live on AWS.

I have built all my infra with Terraform, so I want to only use Terraform to make changes to AWS. The question is, how do I update my ECS Service and keep it in sync with Terraform. The solution I came up with, not sure if I’m reinventing the wheel here, is the following:

  1. Use circleci/aws-ecr to push the newly built image to ECR.
  2. use circleci/aws-ecs -> update-task-definition-from-json to update the task-definition.json
  3. Since I have an updated task-definition.json in the Terraform dir holding the newly built image, it’s only a matter of a terraform apply. I have set it with backend so it should be possible to run it from circleci with circleci/terraform.
  4. I should have the latest container up and running, so the first goal is achieved.
  5. Now, I need to have it in sync. Circleci made changes to the task-definition.json and also at the terraform state. I can give an access key to my github account for the ci to commit the changes.

Is there an easier way to do this?

1 Like