-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
iam-eks-role cannot attach a policy created in the same module using role_policy_arns input #193
Comments
ya, this is an issue related to hashicorp/terraform#4149 the policy you are referring to has to exist before it can be referenced in |
It's possible to write the module in a way that does not encounter this problem by taking a separate argument that is fully known, in this case the "name" of the policy, and using that in the for_each expression. I always prefer that pattern to avoid exactly this issue. |
I don't follow, do you have an example? |
…ules#193) This is the same method as is used in iam-assumable-role-with-oidc. Since the argument to count is a list, not a set, the number of elements doesn't depend on the values, and terraform can decide how many elements are needed before creating the policies.
Yes, if you create a resource and also in the same config/state attempt to reference an attribute of that resource in the key of the for_each expression, then you will encounter the error mentioned in the OP:
Note the "key" of the for_each expression is what must be known. That is important. The problem in this specific case is that the policy is being created in the same state, and so the ARN is unknown in a first apply, and the ARN is used as the for_each key. My solution is to avoid referencing attributes of resources that are likely to be created in the same config/state. Instead of this:
I would use either a map, or an object variable, and construct the for_each key from values that may be known in advance. Using a
Using an object, you have a lot of flexibility in the data structure. I like lists of objects because it works with the splat operator, but a map of objects would be fine also. Here is a list of objects:
And here is a map of objects, where the map key is used directly as the for_each key expression, and is again an arbitrary value set by the user that presumably represents the policy name...
|
thank you for sharing this @lorengordon - I will dive in tomorrow and check it out |
@bryantbiggs were you ever able to figure out a solution? |
Running into this as well, as I create a policy that this module doesn't have.
EDIT: looks like the above isn't the case, from my testing. I believe there is a way around it by using a more defined input, I'm just not sure what that would be. EDIT (again): @lorengordon's solution seems to be what I was thinking of. Not sure why my brain completely skipped over your comment. 😄 It would also be nice to simply add a |
PR is up to resolve this if anyone wants to give it a try #250 |
And big thank you to @lorengordon for pointing out the workaround, this will help a lot as well as in other modules so thank you |
This issue has been resolved in version 5.0.0 🎉 |
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. |
Description
When using iam-eks-role i cannot pass a role_policy_arn i created in the same module
Versions
Reproduction
Using the code snippet below and
Code Snippet to Reproduce
Expected behavior
Policy should be attached
Actual behavior
I get the error below
Terminal Output
Additional context
Using
I am able to attach a policy.
Since this is a common policy i can user terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks, but for a custom policy it wouldn't work
The text was updated successfully, but these errors were encountered: