Help us understand the problem. What is going on with this article?

terraform - 最新のタスクが実行されない

はじめに

自己紹介
Golangをメインにサーバーサイドエンジニアをやってます。
Twitter

(Error)terraformで作成したECSが古いタスクを実行している

service XXXXX was unable to place a task because no container instance met all of its requirements. The closest matching container-instance XXXXXX is already using a port required by your task. For more information, see the Troubleshooting section.

原因

  • 古いリビジョンのタスクが実行されていてポートを専有している。
  • terraform apply するタスクが最新のリビジョンになっていない。

解決策

  • tfファイルの task_definition で最新のリビジョンを明示する。

ソースコード

resource "aws_ecs_service" "dev" {
  name                    = "${var.resource_base_name}"
  cluster                 = "${aws_ecs_cluster.this.id}"
  # これ ↓↓↓↓↓
  task_definition         = "${aws_ecs_task_definition.this.family}:${max("${aws_ecs_task_definition.this.revision}", "${data.aws_ecs_task_definition.this.revision}")}"
  # 他のリソース定義は省略
}

data "aws_ecs_task_definition" "dev" {
  task_definition = "${aws_ecs_task_definition.this.family}"
}

参考

terraform - Data Source: aws_ecs_task_definition

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away