hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.74k stars 9.1k forks source link

ECS with CodeDeploy Blue/Green #12703

Open ahmari6 opened 4 years ago

ahmari6 commented 4 years ago

Community Note

Terraform Version

11.14

Affected Resource(s)

Terraform Configuration Files

https://www.terraform.io/docs/providers/aws/r/codedeploy_deployment_group.html#blue-green-deployments-with-ecs

deployment_controller {
  type = "${var.codebuild_deployment == "true" ? "CODE_DEPLOY" : "ECS"}"
}

Expected Behavior

Terraform should up update task definition value of ECS Service.

Actual Behavior

Error: Error applying plan:

1 error occurred:
    * module.service_task.aws_ecs_service.default: 1 error occurred:
    * aws_ecs_service.default: Error updating ECS Service (arn:aws:ecs:eu-west-1:123456789:service/service-dev-cluster/service-reference-v2-dev-123456abc): InvalidParameterException: Unable to update task definition on services with a CODE_DEPLOY deployment controller. Use AWS CodeDeploy to trigger a new deployment.

When CODE_DEPLOY deployment controller type is utilized with ECS Service, Terraform fails to perform necessary changes.

This behavior makes the whole ECS BLUE/GREEN deployment impossible when deployed with Terraform.

Steps to Reproduce

  1. switch to CODE_DEPLOY deployment type with ECS Service
  2. change aws_ecs_service.task_definition
  3. apply

References

https://github.com/terraform-providers/terraform-provider-aws/issues/6802

ahmari6 commented 4 years ago

CloudFormation now supports CodeDeploy with ECS.

https://aws.amazon.com/about-aws/whats-new/2020/05/aws-cloudformation-now-supports-blue-green-deployments-for-amazon-ecs/

justinretzolk commented 2 years ago

Hey @ahmari6 šŸ‘‹ Thank you for taking the time to file this. Given that there's been a number of Terraform and AWS Provider releases since you initially filed it, can you confirm if you're still experiencing this behavior?

HoussemCharf commented 2 years ago

@justinretzolk, I can confirm here.

Terraform version

1.0.4

Affected resources

aws_3.48.0

justinretzolk commented 2 years ago

Thank you for confirming @HoussemCharf! I've marked this as a bug so that we can take a look into it as soon as possible.

anton-demydov-zoral commented 2 years ago

any updates on this?

rtizzy commented 1 year ago

@justinretzolk This issue is multiple years old.

Is this on the roadmap at all?

nihauc12 commented 1 year ago

šŸ‘‹

elijahchancey commented 3 months ago

This is still an issue with version 5.53.0.

I have this is my aws_ecs_service:

deployment_controller {
    type = "CODE_DEPLOY"
  }

If I declare task_definition, I get this error:

  Error: updating ECS Service (arn:aws:ecs:eu-central-1:REDACTED:service/stage-api/main-api): InvalidParameterException: Unable to update task definition on services with a CODE_DEPLOY deployment controller. Use AWS CodeDeploy to trigger a new deployment.

If I do not declare task_definition, I get this error:

   InvalidParameterException: Family should not be null or empty.

I'll pay someone $100 if they get this bug fixed by June 23rd!

anton-demydov-zoral commented 3 months ago

@elijahchancey tbh I forgot this thread but we got it working. Mostly with this article https://medium.com/@ywg/blue-green-deployment-on-aws-ecs-with-terraform-7dfd67502b5b

The thing is after the deployment with terraform you have to initialize codedeploy with aws cli:

 export TASK_DEFINITION=\$(aws ecs describe-task-definition \
                            --task-definition arn:aws:ecs:us-east-1:ACCOUNT:task-definition/SERVICE-${current_env}| jq .taskDefinition.taskDefinitionArn)
                            envsubst < appspec-template.yaml > appspec-template_rendered.yaml
                            aws deploy create-deployment --cli-input-yaml file://appspec-template_rendered.yaml