Skip to content

Commit fb65123

Browse files
authored
fix(codebuild): take the account & region of an imported Project from its ARN (#13708)
This is needed to correctly use CodeBuild in CodePipeline (which needs to know whether the Project is from a different account/region). Fixes #13694 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 294f546 commit fb65123

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

packages/@aws-cdk/aws-codebuild/lib/project.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,14 +639,19 @@ export interface BindToCodePipelineOptions {
639639
export class Project extends ProjectBase {
640640

641641
public static fromProjectArn(scope: Construct, id: string, projectArn: string): IProject {
642+
const parsedArn = Stack.of(scope).parseArn(projectArn);
643+
642644
class Import extends ProjectBase {
643645
public readonly grantPrincipal: iam.IPrincipal;
644646
public readonly projectArn = projectArn;
645-
public readonly projectName = Stack.of(scope).parseArn(projectArn).resourceName!;
647+
public readonly projectName = parsedArn.resourceName!;
646648
public readonly role?: iam.Role = undefined;
647649

648650
constructor(s: Construct, i: string) {
649-
super(s, i);
651+
super(s, i, {
652+
account: parsedArn.account,
653+
region: parsedArn.region,
654+
});
650655
this.grantPrincipal = new iam.UnknownPrincipal({ resource: this });
651656
}
652657
}

packages/@aws-cdk/aws-codebuild/test/test.project.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,6 +1386,7 @@ export = {
13861386

13871387
test.done();
13881388
},
1389+
13891390
'can override build timeout'(test: Test) {
13901391
// GIVEN
13911392
const stack = new cdk.Stack();
@@ -1407,4 +1408,18 @@ export = {
14071408
test.done();
14081409
},
14091410
},
1411+
1412+
'can be imported': {
1413+
'by ARN'(test: Test) {
1414+
const stack = new cdk.Stack();
1415+
const project = codebuild.Project.fromProjectArn(stack, 'Project',
1416+
'arn:aws:codebuild:us-west-2:123456789012:project/My-Project');
1417+
1418+
test.equal(project.projectName, 'My-Project');
1419+
test.equal(project.env.account, '123456789012');
1420+
test.equal(project.env.region, 'us-west-2');
1421+
1422+
test.done();
1423+
},
1424+
},
14101425
};

0 commit comments

Comments
 (0)