Terraform To Deploy Docker Images To AWS ECS Fargate
Terraform To Deploy Docker Images To AWS ECS Fargate

CI/CD — Force Redeploy AWS ECS Fargate For Same Docker Image NameTag With Terraform

Amith Kumar
3 min readMar 12, 2021

--

Often wondered, how do you force AWS ECS Fargate to redeploy with your CI/CD pipeline when nothing changed in the terraform script other than the code rebuild of the docker image with the same tag?

You certainly don’t want to see this in your CI/CD pipeline with terraform apply:

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Terraform AWS provider has this attribute force_new_deployment under aws_ecs_service, which if set to true should force redeploy with terraform apply.

resource "aws_ecs_service" "main" {
name = "my-app-service"
cluster = aws_ecs_cluster.main.id
task_definition = aws_ecs_task_definition.app.arn
desired_count = 2
launch_type = "FARGATE"
force_new_deployment = true

That attribute directly corresponds to the AWS ECS service flag.

AWS ECS Fargate Update Service Configuration, showing `Force New Deployment` field
AWS ECS Fargate Update Service Configuration

Why should it work?

If you use AWS console (GUI), update the service definition with Force new deployment set to true, and it will re-deploy the tasks. AWS…

--

--