Skip to content

Commit

Permalink
feat(aws-codepipeline): Pipeline now accepts existing IAM role (#2587)
Browse files Browse the repository at this point in the history
Fixes #2572.
  • Loading branch information
AlexChesters authored and rix0rrr committed May 21, 2019
1 parent 7cb8e5e commit eb35807
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
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 @@ -153,7 +160,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 @@ -200,7 +207,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();
},
},
};

0 comments on commit eb35807

Please sign in to comment.