Skip to content
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

feat(aws-codepipeline): Pipeline now accepts existing IAM role #2587

Merged
merged 4 commits into from
May 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ export interface PipelineProps {
*/
readonly artifactBucket?: s3.IBucket;

/**
* The IAM role to be assumed by this Pipeline.
*
* @default a new IAM role will be created.
*/
readonly role?: iam.IRole;

/**
* Indicates whether to rerun the AWS CodePipeline pipeline after you update it.
*/
Expand Down Expand Up @@ -185,7 +192,7 @@ export class Pipeline extends PipelineBase {
* The IAM role AWS CodePipeline will use to perform actions or assume roles for actions with
* a more specific IAM role.
*/
public readonly role: iam.Role;
public readonly role: iam.IRole;

/**
* ARN of this pipeline
Expand Down Expand Up @@ -233,7 +240,8 @@ export class Pipeline extends PipelineBase {
}
this.artifactBucket = propsBucket;

this.role = new iam.Role(this, 'Role', {
// If a role has been provided, use it - otherwise, create a role.
this.role = props.role || new iam.Role(this, 'Role', {
assumedBy: new iam.ServicePrincipal('codepipeline.amazonaws.com')
});

Expand Down
32 changes: 32 additions & 0 deletions packages/@aws-cdk/aws-codepipeline/test/test.pipeline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { expect, haveResourceLike } from '@aws-cdk/assert';
import iam = require('@aws-cdk/aws-iam');
import cdk = require('@aws-cdk/cdk');
import { Test } from 'nodeunit';
import codepipeline = require('../lib');

// tslint:disable:object-literal-key-quotes

export = {
'Pipeline': {
'can be passed an IAM role during pipeline creation'(test: Test) {
const stack = new cdk.Stack();
const role = new iam.Role(stack, 'Role', {
assumedBy: new iam.ServicePrincipal('codepipeline.amazonaws.com')
});
new codepipeline.Pipeline(stack, 'Pipeline', {
role
});

expect(stack, true).to(haveResourceLike('AWS::CodePipeline::Pipeline', {
"RoleArn": {
"Fn::GetAtt": [
"Role1ABCC5F0",
"Arn",
]
}
}));

test.done();
},
},
};