how to preserve older aws ecs taskdefinition revision when creating creating a new one using terraform

Viewed 771

I am creating ecs taskDefinition using terraform.

resource "aws_ecs_task_definition" "tktest_terraform-td" {
  family = "nodejs-webapp"
  container_definitions = "${templatefile("${path.module}/taskdefinition/service-td.tpl", { webapp_docker_image = "${var.webapp_docker_image_name}:${var.webapp_docker_image_tag}"})}"
}

When ever there is a changes to the taskdefinition a new revision is created but the problem is the older revision is gets deleted.

Is it possible to create a new revision but the same time preserve the older revision?

1 Answers

This is long-lasting issue with task definition documented and discussed on GitHub Issues.

So far, the issue is open, and the workaround reported is to manually remove current version of the task from the TF state. In your case it would be:

# we can still get the task definition diff at this point, which we care about
terraform plan

# remove from state so that task definition is not destroyed, and we're able to rollback in the future if needed
terraform state rm aws_ecs_task_definition.tktest_terraform-td

# diff will show a brand new task definition created, but that's ok because we got the diff in step 1
terraform apply
Related