-
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
provider/aws: aws_iam_role_policy add support for managed IAM policies #2100
Comments
👍 |
We do currently have a resource "aws_iam_role_policy" "test_policy" {
name = "test_policy"
role = "${aws_iam_role.test_role.id}"
policy_arn = "${aws_iam_policy.policy.arn}"
}
resource "aws_iam_policy" "policy" {
name = "test_policy"
path = "/"
description = "My test policy"
policy = # omitted
}
resource "aws_iam_role" "test_role" {
name = "test_role"
assume_role_policy = # omitted
} and then invoke |
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html this page describes the process when doing it with the awscli toolkit. |
Also, another interesting bit of information I found when debugging this earlier: For AWS managed policies and customer managed policies, the policy's Version element must be set to 2012-10-17. For inline policies, the policy's Version element can be set to 2012-10-17 or to 2008-10-17. We recommend that you set the Version element to 2012-10-17 for all policies. Found here: https://docs.aws.amazon.com/IAM/latest/UserGuide/policies_managed-vs-inline.html Might be helpful to help you test. |
I think this could be better achieved using similar logic to #2273 The association of a policy with a user/role/group could be implemented as:
The AWS api describes (user/role/group) as having almost identical functionality: This would also simplify the syntax to one association per policy instead of requiring a refactor of either aws_iam_policy_(user/role/group). Makes it interesting to think of associations as resources, but this seems to be the best way right now according to #1419 and other issues. Also, I think the mappings should be 1-to-many so that multiple users/roles/groups can be addressed with a single policy association. |
The implementation of The simple case is that you have created an IAM Policy outside of Terraform and it is attached to roles and users that are not controller by Terraform. If you then use Terraform to create a role and attach the policy to it, it succeeds on the the first |
@johnrengelman have you tried |
My use case is attaching a policy to a role. |
Understood. I was asking because I referred to the source code of |
Yeah, I'm not doing an user<-> group control with Terraform, so I don't know. |
Hello! Sorry for the delay. We did merge #2395 which claims to implement this behavior, so I'm going to close this issue now. Let me know if you believe that is in error, or have other questions. Thanks for writing in and discussing! |
@catsby my comments are with respect to the implement in #2395. |
@johnrengelman This seems like a major problem. We had 2 different roles referencing the AWS ReadOnly policy. When TF detached that policy from the role it was managing it also detached the policy from another role not being reference in TF. @jmccarty3 correct me if I'm wrong on what we saw. |
What we saw from the output was:
This resulted in the behavior @sstarcher mentioned. The statement that created the above log:
|
+1 - the current behavior for policy attachments is not very conducive to reuse and modularization in complex projects for the reasons stated above - the attachment has to be handled once and managed by terraform entirely. For our scenario, we wanted to use terraform to attach ECS Service Role and ECS Instance Role to various bits of infra. We were surprised that some non-terraform-managed infrastructure kept losing these (standard AWS) policy attachments each time we destroyed our terraform-managed infra. Finally we tracked it down to this behavior and then the big warning comment added in the docs triggered our understanding. |
There's nothing in the AWS API that's forcing this particular implementation, I highly suggest that an alternative implementation that is closer to |
Hi All. I've tried to get the functionality you're all requesting implemented in #4016 Feel free to pull down that branch and test if you'd like. |
@johnrengelman let me know that this issue is addressed by my PR for issue #4165 which is also about the issues with |
Can someone explain (or document) why this resource has a required "name" argument? The common idiom for attachment resources (based on sns/lambda/dynamo attachments) is to provide source and target(s) and no name, since it doesn't really represent an AWS resource, justa logical link between resources. |
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. |
Currently
aws_iam_role_policy
supports only attachment of inline policies toaws_iam_role
. Recently Amazon introduced managed IAM policies and recommends using them over inline policies. It would be nice if Terraform supports both types of policies.The text was updated successfully, but these errors were encountered: