使用 terraform 创建新版本时如何保留旧的 aws ecs taskdefinition 修订版

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

我正在使用 terraform 创建 ecs taskDefinition。

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}"})}"
}

只要任务定义发生变化,就会创建一个新修订版,但问题是旧修订版会被删除。

是否可以在创建新修订版的同时保留旧修订版?

这是在 GitHub Issues 上记录和讨论的任务定义的长期问题。

到目前为止,问题已解决,报告的解决方法是手动从 TF 状态中删除任务的当前版本。在你的情况下它将是:

# 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