-
Notifications
You must be signed in to change notification settings - Fork 4k
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
fix(iam): support adding permissions to imported roles #2805
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -260,5 +260,32 @@ export = { | |
test.deepEqual(importedRole.roleArn, 'arn:aws:iam::123456789012:role/S3Access'); | ||
test.deepEqual(importedRole.roleName, 'S3Access'); | ||
test.done(); | ||
}, | ||
|
||
'add policy to imported role'(test: Test) { | ||
// GIVEN | ||
const stack = new Stack(); | ||
const importedRole = Role.fromRoleArn(stack, 'ImportedRole', 'arn:aws:iam::123456789012:role/MyRole'); | ||
|
||
// WHEN | ||
importedRole.addToPolicy(new PolicyStatement() | ||
.addAction('s3:*') | ||
.addResource('xyz')); | ||
|
||
// THEN | ||
expect(stack).to(haveResource('AWS::IAM::Policy', { | ||
PolicyDocument: { | ||
Statement: [ | ||
{ | ||
Action: "s3:*", | ||
Effect: "Allow", | ||
Resource: "xyz" | ||
} | ||
], | ||
Version: "2012-10-17" | ||
}, | ||
Roles: [ "MyRole" ] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I understand this test. Where does the Role with the logical ID There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh wait, is this the physical name of the Role? Does that work in CFN? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CFN is just doing a put-role-policy call with this parameter. |
||
})); | ||
test.done(); | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The methods
addToPolicy
andattachInlinePolicy
are the same as in theRole
class. I wonder whether we could use inheritance here to remove the duplication.