Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 7 additions & 2 deletions packages/@aws-cdk/aws-codebuild/lib/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,14 +639,19 @@ export interface BindToCodePipelineOptions {
export class Project extends ProjectBase {

public static fromProjectArn(scope: Construct, id: string, projectArn: string): IProject {
const parsedArn = Stack.of(scope).parseArn(projectArn);

class Import extends ProjectBase {
public readonly grantPrincipal: iam.IPrincipal;
public readonly projectArn = projectArn;
public readonly projectName = Stack.of(scope).parseArn(projectArn).resourceName!;
public readonly projectName = parsedArn.resourceName!;
public readonly role?: iam.Role = undefined;

constructor(s: Construct, i: string) {
super(s, i);
super(s, i, {
account: parsedArn.account,
region: parsedArn.region,
});
this.grantPrincipal = new iam.UnknownPrincipal({ resource: this });
}
}
Expand Down
15 changes: 15 additions & 0 deletions packages/@aws-cdk/aws-codebuild/test/test.project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,7 @@ export = {

test.done();
},

'can override build timeout'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
Expand All @@ -1003,4 +1004,18 @@ export = {
test.done();
},
},

'can be imported': {
'by ARN'(test: Test) {
const stack = new cdk.Stack();
const project = codebuild.Project.fromProjectArn(stack, 'Project',
'arn:aws:codebuild:us-west-2:123456789012:project/My-Project');

test.equal(project.projectName, 'My-Project');
test.equal(project.env.account, '123456789012');
test.equal(project.env.region, 'us-west-2');

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