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
aws_ecs_task_definition overwrites previous revision #258
Comments
This is expected behavior - i use some code.
this example worked with Terraform v0.9.2 but not worked with Terraform 0.9.11.- may be bug in newst version of tf |
I dealt with it by adding a lifecycle ignore to the task definition and service: resource "aws_ecs_task_definition" "task" {
...
lifecycle = {
ignore_changes = ["*"]
}
}
resource "aws_ecs_service" "test" {
...
lifecycle = {
ignore_changes = ["task_definition"]
}
} |
+1 We hope to see a solution to this issue soon, thanks Hashi for the new tag.... here's to hoping this is moving along. @adamgotterer work around is viable, so long as you are able to manually enable and disable those ignore changes attributes. |
from aws cli about --task-definition: The family and revision (family:revision ) or full ARN of the task definition to run in your service. If a revision is not specified, the latest ACTIVE revision is used. Just use family only. It's still doesn't solve issue with showing changes like: |
+1 We shouldn't need to ignore all changes on the task_definition resource, only on the service. |
It would be very useful to have a flag that would not deregister task definitions when a new one is created. In our case, being able to rollback a service to a previous version in case of bugs is something we'd like to have available. |
I've been running into this issue for a while and I used lifecycle as bandaid solution. It would be nice to have a more solid solution. |
Using the lifecycle still seem to destroy the old task definition, not sure how you all are using it as workaround for the overwrite issue. any help would be appreciated |
Old task revisions are marked as inactive and can be re activated if needed... |
Hi guys, just want to share my solution - I just remove it from state after creation as I dont need Terraform to manage it anymore (its in revision and thats it).
So next time new revision is created and the old one remains. |
@LiborVilimekMassive how this work ? because when I applied the state rm I must import the task definition that is marked as active or terraform must to create the task definition. |
@braybaut - the So in terraform scripts I have
Then I basically call these two commands
Next time these scripts are executed (and something has changed in task definition), the terraform does not know about the previous task definition (as it is not in its state) and therefore creating new version instead and dont delete old version. I suppose that you can even do the other way around - remove it from state before apply and it would work as well. |
@LiborVilimekMassive yes i agree with this, but this is my issue: I have task defitinion resource and service resource, this is my service resource: `An execution plan has been generated and is shown below.
Terraform will perform the following actions:
Plan: 1 to add, 0 to change, 0 to destroy. if I try to remove the resource from state, terraform must create the resource again :c :c |
Task definition revisions are immutable so Terraform is unable to just update this resource and instead needs to delete the old revision and create a new one. This isn't helpful if you still want access to the old task definition such as if you are using another system to manage rollbacks etc as you are unable to roll a service back to an inactive task definition. Closes hashicorp#258
Agree with @LiborVilimekMassive's solution being the closest we seem to get to the ideal state. However, with Ideally, as @binarydud said, we just don't want Terraform to deregister our old task definitions while still showing changes between old and new. EDIT: For those following, we've found a decent workaround # 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.main
# diff will show a brand new task definition created, but that's ok because we got the diff in step 1
terraform apply |
Is it working for someone ? It is not for me.
|
My workaround was to remove the resource from the state file after apply (not after plan) - this is way better as it actually shows the diff, thanks for sharing! |
@FrederikNygaardSvendsen doesn't it mean that you end up in exactly same situation next time you run plan?
|
I'm curious why this is still an issue. aws_launch_template does the right thing and the old templates are retained while only adding new templates if Terraform detects a change. Why can't the same mechanism exist for Task Definitions? |
Any plans on revisiting this issue? |
Would also love to see some news ;) |
Bumping up :) seems like the community wants it 🙏 |
One liner if you have multiple task-definitions that you want to remove from the state after the apply:
|
Hi all 👋 Just letting you know that this is issue is featured on this quarters roadmap. If a PR exists to close the issue a maintainer will review and either make changes directly, or work with the original author to get the contribution merged. If you have written a PR to resolve the issue please ensure the "Allow edits from maintainers" box is checked. Thanks for your patience and we are looking forward to getting this merged soon! |
Related: |
This functionality has been released in v3.72.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
Is it just me or this isn't actually fixed? It still tries to destroy when I change container definitions, even with Tried with this: resource "aws_ecs_service" "test" {
name = "test"
cluster = "test"
task_definition = aws_ecs_task_definition.test.arn
}
resource "aws_ecs_task_definition" "test" {
family = "test"
network_mode = "bridge"
container_definitions = jsonencode(["..."])
skip_destroy = true
} Using version 3.73.0. |
Ignore me, it's just that the Terraform plan that is confusing. It looks like it deletes the task definition from AWS while actually it only removes the old one from the Terraform state and keeps the one in AWS. |
Still the task definition gets deregistered |
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. |
This issue was originally opened by @dimahavrylevych as hashicorp/terraform#8740. It was migrated here as part of the provider split. The original body of the issue is below.
Hello community,
I faced an issue while working with
aws_ecs_task_definition
.I have a script:
Im trying to running:
terraform plan
so the part of output looks like: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?
The text was updated successfully, but these errors were encountered: