* terraform: version = 0.12.16
* provider.aws: version = 2.38
* provider.template: version = 2.1
Since this is a problem I met at my company I encrypted the config and log files with your GPG key (51852D87348FFC4C).
I expect the "aws_ecs_service" resources to be created with the matching keys of the generated "aws_ecs_task_definition" resources.
Also I removed the for_each from aws_ecs_cluster because it was causing the same bug.
on ecs.tf line 103, in resource "aws_ecs_service" "ecs-service-***":
103: task_definition = aws_ecs_task_definition.ecs-task-def-***[each.key].arn
|----------------
| aws_ecs_task_definition.ecs-task-def-*** is object with 17 attributes
| each.key is "2"
The given key does not identify an element in this collection value.
terraform initterraform applyUsing Terragrunt, but I don't think this is relevant for this issue.
This is the same exact bug as these, but on different resources (aws_ecs_cluster, aws_ecs_task_definition, and surely others I cannot spot for now):
If you guys can't reproduce the error I'll try to set you up an example repo.
Thanks in advance.
@SherloxFR Thank you for sharing your log and config -- I am still working on a reproduction case (your config references other resources outside of it, so it's not quite ready to go, but I sincerely thank you for including it and the log). Thank you as well for linking up the related issues. Between all of these, I'm going to be working on creating a replication case so I can hunt this down.
@pselle thanks a lot, I can give you the missing files in the config if you need ! (in 12 hours)
@SherloxFR I believe I have a replication now, but thank you!
I've been able to replicate this by creating situations moving from count to for_each -- in some (possibly most? but I'm not hopeful) of my replications, a second apply works, so I will mention that here on the issue while people are working around it.
@pselle well we definitely were not using count previously :confused:
Maybe I can send the previous ecs.tf file we were using ?
EDIT: Basically we didn't removed anything from ecs.tf, just added the for_each and replace the var.desired_count with each.value.desired_count.
@SherloxFR If you'd like to share your previous/a complete replication case (before+after) I have a PR that I believe will fix the underlying issues in the works and would really like to test against it. A little note that there are holidays in the US next week, so there may be some delay, but now that I've been able to replicate (and have a candidate) I'm very enthusiastic about getting this fixed!
@pselle I'm going to build the binary from your branch on my machine and test it against my case, I'll keep you updated :wink:
This is working perfectly with the binary built from your branch ! Thank you very much, I'm not closing this issue until this is released just in case :smile:
Wonderful, thank you so much for testing, @SherloxFR!
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.