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(codepipeline): make Pipeline importable by ARN #3469

Merged
merged 1 commit into from
Jul 29, 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
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();
},
},
};