Skip to content

Commit

Permalink
feat(codepipeline): make Pipeline importable by ARN
Browse files Browse the repository at this point in the history
Fixes aws#3467
  • Loading branch information
skinny85 committed Jul 29, 2019
1 parent 1409a88 commit 1e164cd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ export interface PipelineProps {
}

abstract class PipelineBase extends Resource implements IPipeline {
public abstract pipelineName: string;
public abstract pipelineArn: string;
public abstract readonly pipelineName: string;
public abstract readonly pipelineArn: string;

/**
* Defines an event rule triggered by this CodePipeline.
Expand Down Expand Up @@ -159,6 +159,22 @@ abstract class PipelineBase extends Resource implements IPipeline {
* // ... add more stages
*/
export class Pipeline extends PipelineBase {
/**
* Import a pipeline into this app.
*
* @param scope the scope into which to import this pipeline
* @param id the logical ID of the returned pipeline construct
* @param pipelineArn The ARN of the pipeline (e.g. `arn:aws:codepipeline:us-east-1:123456789012:MyDemoPipeline`)
*/
public static fromPipelineArn(scope: Construct, id: string, pipelineArn: string): IPipeline {
class Import extends PipelineBase {
public readonly pipelineName = Stack.of(scope).parseArn(pipelineArn).resource;
public readonly pipelineArn = pipelineArn;
}

return new Import(scope, id);
}

/**
* The IAM role AWS CodePipeline will use to perform actions or assume roles for actions with
* a more specific IAM role.
Expand Down
12 changes: 12 additions & 0 deletions packages/@aws-cdk/aws-codepipeline/test/test.pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,17 @@ export = {

test.done();
},

'can be imported by ARN'(test: Test) {
const stack = new cdk.Stack();

const pipeline = codepipeline.Pipeline.fromPipelineArn(stack, 'Pipeline',
'arn:aws:codepipeline:us-east-1:123456789012:MyPipeline');

test.equal(pipeline.pipelineArn, 'arn:aws:codepipeline:us-east-1:123456789012:MyPipeline');
test.equal(pipeline.pipelineName, 'MyPipeline');

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

0 comments on commit 1e164cd

Please sign in to comment.