Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: allow aws_ecs_task_definitions to track the latest revision #8449

Closed
dennari opened this issue Aug 24, 2016 · 6 comments
Closed

Comments

@dennari
Copy link

dennari commented Aug 24, 2016

I'm using the AWS Elastic Container Service managed wholly with Terraform. Deploying an aws_ecs_service with a new Docker image means tainting the associated aws_ecs_task_definition and this works great.

An example configuration could look like this:

resource "template_file" "foo" {
  template = "${file("${path.module}/taskDefinitions/foo.json")}"
  vars {
    image_tag = "latest"
  }
  lifecycle {
    ignore_changes = ["vars.image_tag"]
  }
}

resource "aws_ecs_task_definition" "foo" {
  family                = "foo"
  container_definitions = "${template_file.foo.rendered}"
}

resource "aws_ecs_service" "foo" {
  name            = "foo"
  cluster         = "${aws_ecs_cluster.foo.id}"
  task_definition = "${aws_ecs_task_definition.foo.family}:${aws_ecs_task_definition.foo.revision}"
  desired_count   = 2
}

Problems arise when I'd like to restart the service using the AWS API's directly as part of a CI process. The only thing that changes in the states of the associated task definition and service, is the revision number of the task definition (and possibly the image, but this could be handled with ignore_changes). Making an external deployment then results in the following plan:

~ aws_ecs_service.foo
    task_definition: "foo:2" => "foo:1"

i.e., Terraform would like to roll the service back to itse previous state.

It would be great if aws_ecs_task_definition could optionally update its revision to the latest one during the refresh phase iff the only diff is the revision and the refreshed revision is higher.

If there are other ways to achieve Terraform being in sync with the revisions I'd be very interested in hearing them.

@dennari
Copy link
Author

dennari commented Aug 24, 2016

I think another, and more general, way to achieve the described goal would be to also have data aws_ecs_task_definition and a max() interpolation function. Then I could do:

resource "aws_ecs_service" "foo" {
  name            = "foo"
  cluster         = "${aws_ecs_cluster.foo.id}"
  task_definition = "${aws_ecs_task_definition.foo.family}:${max("${aws_ecs_task_definition.foo.revision}","${data.aws_ecs_task_definition.foo.revision}")}"
  desired_count   = 2
}

@RyanBowlby-Reflektion
Copy link

#7230

See the above new data resource. I'm not entirely convinced this is the right solution though. I think using the data resource above only works if the task definition already exists. What is to be done about the very first terraform apply?

@dennari
Copy link
Author

dennari commented Oct 2, 2016

@RyanBowlby-Reflektion, good point. There would need to be logic that'd recognize that both the resource and the datasource are defined and in this case default the datasource's revision to 0 on the initial apply. I agree this sounds a bit complicated and wouldn't allow the datasource to have pretty much any other attributes than the revision, since the other ones probably wouldn't have any acceptable 'initial' value.

That said, for the described use case no other attributes are needed.

@dennari
Copy link
Author

dennari commented Oct 2, 2016

PR #8509 looks great. However it seems to require applying in steps, first creating the task definition resources and then adding the datasources. Please correct me if I'm wrong.

I realize there's also an issue with the image tags. Datasources don't support the ignore_changes lifecycle attribute, so in the described use case the deprecated template_file.foo could not be switched into a datasource.

@stack72
Copy link
Contributor

stack72 commented Feb 8, 2017

Closed via #8509 - this is now a data source that allows you to get the latest version

@stack72 stack72 closed this as completed Feb 8, 2017
@ghost
Copy link

ghost commented Apr 17, 2020

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.

@ghost ghost locked and limited conversation to collaborators Apr 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants