Skip to content
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
15 changes: 14 additions & 1 deletion packages/aws-cdk-lib/aws-codebuild/lib/fleet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as iam from '../../aws-iam';
import { Arn, ArnFormat, IResource, PhysicalName, Resource, Size, Token, UnscopedValidationError, ValidationError } from '../../core';
import { addConstructMetadata } from '../../core/lib/metadata-resource';
import { propertyInjectable } from '../../core/lib/prop-injectable';
import { IFleetRef, FleetReference } from '../../interfaces/generated/aws-codebuild-interfaces.generated';

/**
* Construction properties of a CodeBuild Fleet.
Expand Down Expand Up @@ -175,7 +176,7 @@ export interface ComputeConfiguration {
/**
* Represents a Fleet for a reserved capacity CodeBuild project.
*/
export interface IFleet extends IResource, iam.IGrantable, ec2.IConnectable {
export interface IFleet extends IResource, iam.IGrantable, ec2.IConnectable, IFleetRef {
/**
* The ARN of the fleet.
* @attribute
Expand Down Expand Up @@ -230,6 +231,12 @@ export class Fleet extends Resource implements IFleet {
public readonly fleetName = Arn.split(fleetArn, ArnFormat.SLASH_RESOURCE_NAME).resourceName!.split(':')[0];
public readonly fleetArn = fleetArn;

public get fleetRef(): FleetReference {
return {
fleetArn: this.fleetArn,
};
}

public get computeType(): FleetComputeType {
throw new UnscopedValidationError('Cannot retrieve computeType property from an imported Fleet');
}
Expand Down Expand Up @@ -270,6 +277,12 @@ export class Fleet extends Resource implements IFleet {
*/
public readonly environmentType: EnvironmentType;

public get fleetRef(): FleetReference {
return {
fleetArn: this.fleetArn,
};
}

// Lazily created connections. Only created if `vpc` is provided in props.
private _connections?: ec2.Connections;

Expand Down
10 changes: 9 additions & 1 deletion packages/aws-cdk-lib/aws-codebuild/lib/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import * as secretsmanager from '../../aws-secretsmanager';
import { Annotations, ArnFormat, Aws, Duration, IResource, Lazy, Names, PhysicalName, Reference, Resource, SecretValue, Stack, Token, TokenComparison, Tokenization, UnscopedValidationError, ValidationError } from '../../core';
import { addConstructMetadata, MethodMetadata } from '../../core/lib/metadata-resource';
import { propertyInjectable } from '../../core/lib/prop-injectable';
import { IProjectRef, ProjectReference } from '../../interfaces/generated/aws-codebuild-interfaces.generated';

const VPC_POLICY_SYM = Symbol.for('@aws-cdk/aws-codebuild.roleVpcPolicy');

Expand Down Expand Up @@ -71,7 +72,7 @@ export interface ProjectNotifyOnOptions extends notifications.NotificationRuleOp
readonly events: ProjectNotificationEvents[];
}

export interface IProject extends IResource, iam.IGrantable, ec2.IConnectable, notifications.INotificationRuleSource {
export interface IProject extends IResource, iam.IGrantable, ec2.IConnectable, notifications.INotificationRuleSource, IProjectRef {
/**
* The ARN of this Project.
* @attribute
Expand Down Expand Up @@ -265,6 +266,13 @@ abstract class ProjectBase extends Resource implements IProject {
/** The IAM service Role of this Project. */
public abstract readonly role?: iam.IRole;

public get projectRef(): ProjectReference {
return {
projectName: this.projectName,
projectArn: this.projectArn,
};
}

/**
* Actual connections object for this Project.
* May be unset, in which case this Project is not configured to use a VPC.
Expand Down
9 changes: 8 additions & 1 deletion packages/aws-cdk-lib/aws-codebuild/lib/report-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import * as s3 from '../../aws-s3';
import * as cdk from '../../core';
import { addConstructMetadata } from '../../core/lib/metadata-resource';
import { propertyInjectable } from '../../core/lib/prop-injectable';
import { IReportGroupRef, ReportGroupReference } from '../../interfaces/generated/aws-codebuild-interfaces.generated';

/**
* The interface representing the ReportGroup resource -
* either an existing one, imported using the
* `ReportGroup.fromReportGroupName` method,
* or a new one, created with the `ReportGroup` class.
*/
export interface IReportGroup extends cdk.IResource {
export interface IReportGroup extends cdk.IResource, IReportGroupRef {
/**
* The ARN of the ReportGroup.
*
Expand Down Expand Up @@ -42,6 +43,12 @@ abstract class ReportGroupBase extends cdk.Resource implements IReportGroup {
protected abstract readonly exportBucket?: s3.IBucket;
protected abstract readonly type?: ReportGroupType;

public get reportGroupRef(): ReportGroupReference {
return {
reportGroupArn: this.reportGroupArn,
};
}

public grantWrite(identity: iam.IGrantable): iam.Grant {
const typeAction = this.type === ReportGroupType.CODE_COVERAGE ? 'codebuild:BatchPutCodeCoverages' : 'codebuild:BatchPutTestCases';
const ret = iam.Grant.addToPrincipal({
Expand Down
6 changes: 3 additions & 3 deletions packages/aws-cdk-lib/aws-events-targets/lib/codebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface CodeBuildProjectProps extends TargetBaseProps {
*/
export class CodeBuildProject implements events.IRuleTarget {
constructor(
private readonly project: codebuild.IProject,
private readonly project: codebuild.IProjectRef,
private readonly props: CodeBuildProjectProps = {},
) {}

Expand All @@ -46,12 +46,12 @@ export class CodeBuildProject implements events.IRuleTarget {
const role = this.props.eventRole || singletonEventRole(this.project);
role.addToPrincipalPolicy(new iam.PolicyStatement({
actions: ['codebuild:StartBuild'],
resources: [this.project.projectArn],
resources: [this.project.projectRef.projectArn],
}));

return {
...bindBaseTargetConfig(this.props),
arn: this.project.projectArn,
arn: this.project.projectRef.projectArn,
role,
input: this.props.event,
targetResource: this.project,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ScheduleTargetBase, ScheduleTargetBaseProps } from './target';
import { IProject } from '../../aws-codebuild';
import { IProjectRef } from '../../aws-codebuild';
import { IRole, PolicyStatement } from '../../aws-iam';
import { IScheduleTarget } from '../../aws-scheduler';

Expand All @@ -8,16 +8,16 @@ import { IScheduleTarget } from '../../aws-scheduler';
*/
export class CodeBuildStartBuild extends ScheduleTargetBase implements IScheduleTarget {
constructor(
private readonly project: IProject,
private readonly project: IProjectRef,
props: ScheduleTargetBaseProps = {},
) {
super(props, project.projectArn);
super(props, project.projectRef.projectArn);
}

protected addTargetActionToRole(role: IRole): void {
role.addToPrincipalPolicy(new PolicyStatement({
actions: ['codebuild:StartBuild'],
resources: [this.project.projectArn],
resources: [this.project.projectRef.projectArn],
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface CodeBuildStartBuildBatchOptions {
/**
* CodeBuild project to start
*/
readonly project: codebuild.IProject;
readonly project: codebuild.IProjectRef;

/**
* A set of environment variables to be used for this build only.
Expand Down Expand Up @@ -78,7 +78,7 @@ export class CodeBuildStartBuildBatch extends sfn.TaskStateBase {
metricPrefixSingular: 'CodeBuildProject',
metricPrefixPlural: 'CodeBuildProjects',
metricDimensions: {
ProjectArn: this.props.project.projectArn,
ProjectArn: this.props.project.projectRef.projectArn,
},
};

Expand All @@ -97,7 +97,7 @@ export class CodeBuildStartBuildBatch extends sfn.TaskStateBase {
case sfn.IntegrationPattern.RUN_JOB:
policyStatements = [
new iam.PolicyStatement({
resources: [this.props.project.projectArn],
resources: [this.props.project.projectRef.projectArn],
actions: [
'codebuild:StartBuildBatch',
'codebuild:StopBuildBatch',
Expand All @@ -118,7 +118,7 @@ export class CodeBuildStartBuildBatch extends sfn.TaskStateBase {
case sfn.IntegrationPattern.REQUEST_RESPONSE:
policyStatements = [
new iam.PolicyStatement({
resources: [this.props.project.projectArn],
resources: [this.props.project.projectRef.projectArn],
actions: ['codebuild:StartBuildBatch'],
}),
];
Expand All @@ -140,7 +140,7 @@ export class CodeBuildStartBuildBatch extends sfn.TaskStateBase {
return {
Resource: integrationResourceArn('codebuild', 'startBuildBatch', this.integrationPattern),
...this._renderParametersOrArguments({
ProjectName: this.props.project.projectName,
ProjectName: this.props.project.projectRef.projectName,
EnvironmentVariablesOverride: this.props.environmentVariablesOverride
? this.serializeEnvVariables(this.props.environmentVariablesOverride)
: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface CodeBuildStartBuildOptions {
/**
* CodeBuild project to start
*/
readonly project: codebuild.IProject;
readonly project: codebuild.IProjectRef;
/**
* A set of environment variables to be used for this build only.
*
Expand Down Expand Up @@ -73,7 +73,7 @@ export class CodeBuildStartBuild extends sfn.TaskStateBase {
metricPrefixSingular: 'CodeBuildProject',
metricPrefixPlural: 'CodeBuildProjects',
metricDimensions: {
ProjectArn: this.props.project.projectArn,
ProjectArn: this.props.project.projectRef.projectArn,
},
};

Expand All @@ -83,7 +83,7 @@ export class CodeBuildStartBuild extends sfn.TaskStateBase {
private configurePolicyStatements(): iam.PolicyStatement[] {
let policyStatements = [
new iam.PolicyStatement({
resources: [this.props.project.projectArn],
resources: [this.props.project.projectRef.projectArn],
actions: [
'codebuild:StartBuild',
'codebuild:StopBuild',
Expand Down Expand Up @@ -121,7 +121,7 @@ export class CodeBuildStartBuild extends sfn.TaskStateBase {
return {
Resource: integrationResourceArn('codebuild', 'startBuild', this.integrationPattern),
...this._renderParametersOrArguments({
ProjectName: this.props.project.projectName,
ProjectName: this.props.project.projectRef.projectName,
EnvironmentVariablesOverride: this.props.environmentVariablesOverride
? this.serializeEnvVariables(this.props.environmentVariablesOverride)
: undefined,
Expand Down
Loading