-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Problems referencing a new resource using for_each #23026
Comments
I'm seeing the same issue. If I comment out the dependent resources, run terraform to create the roles and then uncomment the dependents and build them, it all works. From a clean state, it complains about the role collection key. I tried adding an explicit depends_on but that didn't help. |
Thanks for providing your debug output, @kinghuang. I'm having difficulty replicating this with a simplified use case, since I'm missing more of your config -- perhaps some of the issue lies there? I will add that when you get the invalid index like this:
Note that the output tells you that the resource is an object with 7 attributes -- that signals to me that this is likely pointing to an individual resource somehow, and of course, your single resource does not have a key of the name you're looking for -- you're looking for an instance keyed with that name. This line in your debug log:
Also makes me wonder if you still see this issue with an upgrade to the latest (now 0.12.13) version of Terraform? We made a fairly significant change in how we fetch resources, namely #22846, that could possibly impact this. Additionally, thanks for linking the other similar issue to yours :) |
I'll give this a try in the latest release and report back, hopefully by next week! |
@Richard-Payne if you're interested/able, I'd appreciate sharing a config (ideally simplified, and of course, less any secrets) that replicates this case. |
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. |
I added the
aws_iam_policy
andaws_iam_role_policy_attachment
resources shown below to an existing Terraform configuration. They both usefor_each
to create a resource per entry in thelocal.node_group_names_with_rexray_plugins
map.During plan, I'm getting an Invalid index error. The
aws_iam_role_policy_attachment
is saying that aaws_iam_policy
resource doesn't already exist. But, it should be created as part of this plan & apply.Terraform Version
Terraform Configuration Files
Added the following:
Debug Output
Debug Output
Crash Output
N/A
Expected Behavior
aws_iam_policy
andaws_iam_role_policy_attachment
resources should be created, based on thelocal.node_group_names_with_rexray_plugins
map.Actual Behavior
Terraform reports that the
aws_iam_policy
policy "metadata" thataws_iam_role_policy_attachment
is referencing doesn't already exist. But, it should be created as part of this plan & apply.Steps to Reproduce
I had an existing Terraform configuration that I added the above two resources to.
If I destroy the rest of the resources in the project and apply everything together, then no error occurs.
Additional Context
N/A
References
N/A
The text was updated successfully, but these errors were encountered: