-
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
for_each fails when the number of resources should be known #30838
Comments
Hi @jsimoni, Unfortunately what you observed here does seem to be Terraform working as designed, though I agree it's an annoying edge to the design. The root problem here is that because map elements must have unique keys Terraform cannot know the number of elements in any map constructed with unique keys: Terraform has no way to prove that two of the keys won't end up having the same value. Furthermore though, even ignoring the issue of number of elements for So as commonly recommended in these situations, the answer is to set the map keys to include only known values and place unknown values such as a server-generated ID only in the values of the map elements. Terraform will then have the tracking keys it needs but can still take into account the unknown ID for use when populating arguments of the resource. |
documented anywhere? because it worked for me!
|
The intended documentation for this is Limitations on values in We do have an updated error message for this case which aims to be more specific but I think that won't appear until the v1.2 release because it was a relatively recent change. Maybe we also updated the docs as part of that and so they too will appear with the v1.2 release, but if not it does seem like it would be helpful to spell out concretely the idea of using only known values in the key but being able to use unknown values in the value of each element. |
I just confirmed in #30327 that the new messaging includes a specific suggestion to make the keys be known during apply and put unknown values only in the value:
There's a limit to how specific we can be in error messages without making them super verbose but hopefully this new message coming in v1.2 would've been a better hook for learning how to move forward. It looks like I did not update the documentation as part of that PR so there is still some potential for adding similar language to the documentation (where we can potentially elaborate more and show some examples) but at least the in-product messaging will be more accurate starting at the next minor release. |
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. |
Description
I am getting the following error message when the number of resources to create is known at plan
Terraform Version
Terraform Configuration Files
...
Debug Output
Expected Behavior
AWS SSO Group would be successfully assigned with the specified Accounts and Permission Sets
Actual Behavior
Steps to Reproduce
Additional Context
If I use -target as suggested elsewhere (4149) to provision the permission set first, then the assignments works. However, the explanations I've seen for this error is that Terraform is unable to determine the number of resources to provision at plan so it fails. But in this case, while the arn of the permission set would be unknown, Terraform can determine the number of assignments to create.
References
The text was updated successfully, but these errors were encountered: