https://pulumi.com logo
#aws
Title
a

alert-raincoat-81485

11/23/2020, 11:33 PM
Folks, How to assign multiple policies to one role. As per example, only one arn is assigned to the role. Is there any way we can assign multiple existing policies.
Copy code
policy = aws.iam.Policy("policy",
    description="A test policy",
    policy="""{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": [
        "ec2:Describe*"
      ],
      "Effect": "Allow",
      "Resource": "*"
    }
  ]
}
""")
test_attach = aws.iam.PolicyAttachment("test-attach",
    users=[user.name],
    roles=[role.name],
    groups=[group.name],
    policy_arn=policy.arn)
b

billowy-army-68599

11/23/2020, 11:35 PM
you can just do this with a standard loop
a

alert-raincoat-81485

11/23/2020, 11:40 PM
that make sense, but so far no API available to attach multiple policies right!
l

little-cartoon-10569

11/23/2020, 11:41 PM
The standard solution is to make a policy with multiple statements.
If you have to use multiple policies, then unfortunately you'll have to do it the long way...
a

alert-raincoat-81485

11/24/2020, 9:03 AM
@little-cartoon-10569 Creating multiple policies it’s still fine for me, but i am looking for a solution where we can attach multiple policies to one role.
l

little-cartoon-10569

11/24/2020, 7:53 PM
As Lee said, you have to use attach them separately, and a loop will handle it. Note that there is an AWS limit of 10 policies per role.
1