diff --git a/packages/aws-cdk-lib/aws-codebuild/lib/fleet.ts b/packages/aws-cdk-lib/aws-codebuild/lib/fleet.ts index 5577f9a6024bf..5a8d54014ac58 100644 --- a/packages/aws-cdk-lib/aws-codebuild/lib/fleet.ts +++ b/packages/aws-cdk-lib/aws-codebuild/lib/fleet.ts @@ -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. @@ -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 @@ -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'); } @@ -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; diff --git a/packages/aws-cdk-lib/aws-codebuild/lib/project.ts b/packages/aws-cdk-lib/aws-codebuild/lib/project.ts index 5f2e975d8b585..60295915e93c2 100644 --- a/packages/aws-cdk-lib/aws-codebuild/lib/project.ts +++ b/packages/aws-cdk-lib/aws-codebuild/lib/project.ts @@ -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'); @@ -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 @@ -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. diff --git a/packages/aws-cdk-lib/aws-codebuild/lib/report-group.ts b/packages/aws-cdk-lib/aws-codebuild/lib/report-group.ts index 8f44a8cb48e2b..f599f08f5c4a0 100644 --- a/packages/aws-cdk-lib/aws-codebuild/lib/report-group.ts +++ b/packages/aws-cdk-lib/aws-codebuild/lib/report-group.ts @@ -6,6 +6,7 @@ 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 - @@ -13,7 +14,7 @@ import { propertyInjectable } from '../../core/lib/prop-injectable'; * `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. * @@ -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({ diff --git a/packages/aws-cdk-lib/aws-events-targets/lib/codebuild.ts b/packages/aws-cdk-lib/aws-events-targets/lib/codebuild.ts index c2b9a37edfe81..a44b6efe2d7ae 100644 --- a/packages/aws-cdk-lib/aws-events-targets/lib/codebuild.ts +++ b/packages/aws-cdk-lib/aws-events-targets/lib/codebuild.ts @@ -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 = {}, ) {} @@ -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, diff --git a/packages/aws-cdk-lib/aws-scheduler-targets/lib/codebuild-start-build.ts b/packages/aws-cdk-lib/aws-scheduler-targets/lib/codebuild-start-build.ts index bb1df6bcf4846..7f1a51c7fc3e4 100644 --- a/packages/aws-cdk-lib/aws-scheduler-targets/lib/codebuild-start-build.ts +++ b/packages/aws-cdk-lib/aws-scheduler-targets/lib/codebuild-start-build.ts @@ -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'; @@ -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], })); } } diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/codebuild/start-build-batch.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/codebuild/start-build-batch.ts index fbb17214e078f..b01befaa7a291 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/codebuild/start-build-batch.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/codebuild/start-build-batch.ts @@ -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. @@ -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, }, }; @@ -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', @@ -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'], }), ]; @@ -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, diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/codebuild/start-build.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/codebuild/start-build.ts index 25b2b026c70ab..a3c6406f842b3 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/codebuild/start-build.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/codebuild/start-build.ts @@ -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. * @@ -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, }, }; @@ -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', @@ -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,