Skip to main content
Blue/green deployments replace running tasks with a new version while keeping the old version alive until traffic has been shifted and validated. This eliminates downtime during deploys and allows fast rollback if the new version fails health checks. This module supports two approaches:

ECS-native blue/green

Configured via deployment_configuration.strategy = "BLUE_GREEN". Managed entirely by ECS without CodeDeploy. Simpler to set up.

CodeDeploy blue/green

Uses ignore_task_definition_changes = true and an external aws_codedeploy_deployment_group. Required when CodeDeploy manages the deployment lifecycle.

ECS-native blue/green

The fargate example uses the ECS-native blue/green strategy with two ALB target groups:
You also need two ALB target groups and two listener rules (production and test):

CodeDeploy blue/green

For CodeDeploy-managed deployments, ECS hands off the deployment lifecycle to CodeDeploy. In this model, CodeDeploy (not Terraform) updates the service’s task definition and load balancer configuration during each deploy.

The role of ignore_task_definition_changes

Set ignore_task_definition_changes = true to instruct the module to ignore changes to the service’s task_definition and load_balancer arguments. This is required because:
  • CodeDeploy changes the task definition during each deployment to point to the new image.
  • CodeDeploy shifts the load balancer from the blue target group to the green target group.
Without this flag, Terraform would conflict with CodeDeploy by trying to revert those changes on the next terraform apply.
Changing ignore_task_definition_changes after the service has been created forces Terraform to destroy and recreate the ECS service. This causes downtime. Decide on this value before the first deployment and do not change it afterward.

Complete CodeDeploy example

Traffic shifting strategies

The deployment_config_name in the aws_codedeploy_deployment_group controls how traffic shifts: You can also define a custom deployment configuration with finer control over step percentages and bake times.

Canary deployments (EC2 capacity)

The ec2-autoscaling example demonstrates a canary strategy using the ECS-native deployment configuration:
This routes 10% of traffic to the new version for 5 minutes before shifting the remainder.