Terraform: aws_ecs_task_definition overwrites previous revision

Created on 8 Sep 2016  ยท  10Comments  ยท  Source: hashicorp/terraform

Hello community,

I faced an issue while working with aws_ecs_task_definition.
I have a script:

data "template_file" "task_definition" {
  template = "${file("task-definitions/service.json")}"
  vars {
    SERVICE_NAME = "test"
    IMAGE_URL = "test:latest"
  }
}

resource "aws_ecs_task_definition" "test" {
    family = "test"
    network_mode = "bridge"
    container_definitions = "${data.template_file.task_definition.rendered}"
}

resource "aws_ecs_service" "test" {
  name = "test"
  cluster = "test"
  task_definition = "${aws_ecs_task_definition.test.arn}"
  desired_count = 2
  deployment_minimum_healthy_percent = 100
}

Im trying to running: terraform plan so the part of output looks like:

-/+ ...
...
 revision:              "24" => "<computed>"
...

While running terraform apply and loging to AWS I see that the new revision has created but the previous one dissapeared.

Question:

Is is possible to implement a flag that will allow me to save previous revisions?

bug provideaws

Most helpful comment

Is there a workaround that prevents aws_ecs_task_definition from creating a new task revision every time terraform apply is run?

All 10 comments

Hi,
this was originally (at the time of creation) intended behaviour to prevent Terraform from "leaking resources" (in this case registered task definitions), but I can see how that might confuse users.

See https://github.com/hashicorp/terraform/issues/8765 which should address this problem that affects couple of resources including ECS TD.
TL;DR after that change we'd be actually leaking resources, but we'd give the user fairly easy way to delete those instead of letting them do it outside of Terraform.

ok, thanks @radeksimko
do you guys have any progress on #8765 ?

Is there a workaround that prevents aws_ecs_task_definition from creating a new task revision every time terraform apply is run?

+1
I think it will be useful to keep previous revision. Maybe I want to rollback after deploy.

+1

FWIW, previous revisions are not actually destroyed, they're just marked "inactive" in AWS. You can mark them active again manually if you need to roll back. However, it would still be great if the task definition resource had an option to leave the previous revision active.

How to workoround this?

You can mark them active again manually if you need to roll back.

Didn't found the way to do that.. Can't do anythink with INACTIVE task-definition revisions. Only list.

A work around is to delete the terraform state before. Then a new resource is created and the old one is not getting inactive.
When you only handle the task definitions for that, it is a usable way.

Instead of deleting the state, you can also perhaps checkout /copy the tf script to a new folder (perhaps with version name) and then run again. Then you get also a new task, but could also destroy the old one sometimes, when you store the state somewhere

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings