Skip to content
Draft
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
21 changes: 20 additions & 1 deletion packages/aws-cdk-lib/aws-codedeploy/lib/ecs/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Construct } from 'constructs';
import { ArnFormat, IResource, Resource, Stack, Arn } from '../../../core';
import { addConstructMetadata } from '../../../core/lib/metadata-resource';
import { propertyInjectable } from '../../../core/lib/prop-injectable';
import { IApplicationRef } from '../../../interfaces/generated/aws-codedeploy-interfaces.generated';
import { CfnApplication } from '../codedeploy.generated';
import { arnForApplication, validateName } from '../private/utils';

Expand All @@ -15,7 +16,7 @@ import { arnForApplication, validateName } from '../private/utils';
* or one defined in a different CDK Stack,
* use the `EcsApplication#fromEcsApplicationName` method.
*/
export interface IEcsApplication extends IResource {
export interface IEcsApplication extends IResource, IApplicationRef {
/** @attribute */
readonly applicationArn: string;

Expand Down Expand Up @@ -60,6 +61,12 @@ export class EcsApplication extends Resource implements IEcsApplication {
class Import extends Resource implements IEcsApplication {
public applicationArn = arnForApplication(Stack.of(scope), ecsApplicationName);
public applicationName = ecsApplicationName;

public get applicationRef() {
return {
applicationName: this.applicationName,
};
}
}

return new Import(scope, id);
Expand All @@ -77,12 +84,24 @@ export class EcsApplication extends Resource implements IEcsApplication {
return new class extends Resource implements IEcsApplication {
public applicationArn = ecsApplicationArn;
public applicationName = Arn.split(ecsApplicationArn, ArnFormat.COLON_RESOURCE_NAME).resourceName ?? '<invalid arn>';

public get applicationRef() {
return {
applicationName: this.applicationName,
};
}
} (scope, id, { environmentFromArn: ecsApplicationArn });
}

public readonly applicationArn: string;
public readonly applicationName: string;

public get applicationRef() {
return {
applicationName: this.applicationName,
};
}

constructor(scope: Construct, id: string, props: EcsApplicationProps = {}) {
super(scope, id, {
physicalName: props.applicationName,
Expand Down
11 changes: 10 additions & 1 deletion packages/aws-cdk-lib/aws-codedeploy/lib/ecs/deployment-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ValidationError } from '../../../core';
import { addConstructMetadata, MethodMetadata } from '../../../core/lib/metadata-resource';
import { propertyInjectable } from '../../../core/lib/prop-injectable';
import { CODEDEPLOY_REMOVE_ALARMS_FROM_DEPLOYMENT_GROUP } from '../../../cx-api';
import { IDeploymentGroupRef } from '../../../interfaces/generated/aws-codedeploy-interfaces.generated';
import { CfnDeploymentGroup } from '../codedeploy.generated';
import { ImportedDeploymentGroupBase, DeploymentGroupBase } from '../private/base-deployment-group';
import { renderAlarmConfiguration, renderAutoRollbackConfiguration } from '../private/utils';
Expand All @@ -18,7 +19,7 @@ import { AutoRollbackConfig } from '../rollback-config';
/**
* Interface for an ECS deployment group.
*/
export interface IEcsDeploymentGroup extends cdk.IResource {
export interface IEcsDeploymentGroup extends cdk.IResource, IDeploymentGroupRef {
/**
* The reference to the CodeDeploy ECS Application that this Deployment Group belongs to.
*/
Expand Down Expand Up @@ -368,6 +369,13 @@ export interface EcsDeploymentGroupAttributes {
* @default EcsDeploymentConfig.ALL_AT_ONCE
*/
readonly deploymentConfig?: IEcsDeploymentConfig;

/**
* The ID of the CodeDeploy Deployment Group.
*
* @default - the ID will be constructed from the application name and deployment group name
*/
readonly deploymentGroupId?: string;
}

@propertyInjectable
Expand All @@ -381,6 +389,7 @@ class ImportedEcsDeploymentGroup extends ImportedDeploymentGroupBase implements
super(scope, id, {
application: props.application,
deploymentGroupName: props.deploymentGroupName,
deploymentGroupId: props.deploymentGroupId,
});
// Enhanced CDK Analytics Telemetry
addConstructMetadata(this, props);
Expand Down
21 changes: 20 additions & 1 deletion packages/aws-cdk-lib/aws-codedeploy/lib/lambda/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Construct } from 'constructs';
import { ArnFormat, IResource, Resource, Stack, Arn } from '../../../core';
import { addConstructMetadata } from '../../../core/lib/metadata-resource';
import { propertyInjectable } from '../../../core/lib/prop-injectable';
import { IApplicationRef } from '../../../interfaces/generated/aws-codedeploy-interfaces.generated';
import { CfnApplication } from '../codedeploy.generated';
import { arnForApplication, validateName } from '../private/utils';

Expand All @@ -15,7 +16,7 @@ import { arnForApplication, validateName } from '../private/utils';
* or one defined in a different CDK Stack,
* use the `LambdaApplication#fromLambdaApplicationName` method.
*/
export interface ILambdaApplication extends IResource {
export interface ILambdaApplication extends IResource, IApplicationRef {
/** @attribute */
readonly applicationArn: string;

Expand Down Expand Up @@ -60,6 +61,12 @@ export class LambdaApplication extends Resource implements ILambdaApplication {
class Import extends Resource implements ILambdaApplication {
public applicationArn = arnForApplication(Stack.of(scope), lambdaApplicationName);
public applicationName = lambdaApplicationName;

public get applicationRef() {
return {
applicationName: this.applicationName,
};
}
}

return new Import(scope, id);
Expand All @@ -77,12 +84,24 @@ export class LambdaApplication extends Resource implements ILambdaApplication {
return new class extends Resource implements ILambdaApplication {
public applicationArn = lambdaApplicationArn;
public applicationName = Arn.split(lambdaApplicationArn, ArnFormat.COLON_RESOURCE_NAME).resourceName ?? '<invalid arn>';

public get applicationRef() {
return {
applicationName: this.applicationName,
};
}
}(scope, id, { environmentFromArn: lambdaApplicationArn });
}

public readonly applicationArn: string;
public readonly applicationName: string;

public get applicationRef() {
return {
applicationName: this.applicationName,
};
}

constructor(scope: Construct, id: string, props: LambdaApplicationProps = {}) {
super(scope, id, {
physicalName: props.applicationName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as cdk from '../../../core';
import { addConstructMetadata, MethodMetadata } from '../../../core/lib/metadata-resource';
import { propertyInjectable } from '../../../core/lib/prop-injectable';
import { CODEDEPLOY_REMOVE_ALARMS_FROM_DEPLOYMENT_GROUP } from '../../../cx-api';
import { IDeploymentGroupRef } from '../../../interfaces/generated/aws-codedeploy-interfaces.generated';
import { CfnDeploymentGroup } from '../codedeploy.generated';
import { ImportedDeploymentGroupBase, DeploymentGroupBase } from '../private/base-deployment-group';
import { renderAlarmConfiguration, renderAutoRollbackConfiguration } from '../private/utils';
Expand All @@ -16,7 +17,7 @@ import { AutoRollbackConfig } from '../rollback-config';
/**
* Interface for a Lambda deployment groups.
*/
export interface ILambdaDeploymentGroup extends cdk.IResource {
export interface ILambdaDeploymentGroup extends cdk.IResource, IDeploymentGroupRef {
/**
* The reference to the CodeDeploy Lambda Application that this Deployment Group belongs to.
*/
Expand Down Expand Up @@ -306,6 +307,13 @@ export interface LambdaDeploymentGroupAttributes {
* @default LambdaDeploymentConfig.CANARY_10PERCENT_5MINUTES
*/
readonly deploymentConfig?: ILambdaDeploymentConfig;

/**
* The ID of the CodeDeploy Deployment Group.
*
* @default - the ID will be constructed from the application name and deployment group name
*/
readonly deploymentGroupId?: string;
}

@propertyInjectable
Expand All @@ -319,6 +327,7 @@ class ImportedLambdaDeploymentGroup extends ImportedDeploymentGroupBase implemen
super(scope, id, {
application: props.application,
deploymentGroupName: props.deploymentGroupName,
deploymentGroupId: props.deploymentGroupId,
});
// Enhanced CDK Analytics Telemetry
addConstructMetadata(this, props);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Construct } from 'constructs';
import { isPredefinedDeploymentConfig } from './predefined-deployment-config';
import { validateName } from './utils';
import * as iam from '../../../aws-iam';
import { Resource, IResource, ArnFormat, Arn, Aws } from '../../../core';
import { Resource, IResource, ArnFormat, Arn, Aws, ValidationError } from '../../../core';
import { addConstructMetadata } from '../../../core/lib/metadata-resource';
import { propertyInjectable } from '../../../core/lib/prop-injectable';
import { IBaseDeploymentConfig } from '../base-deployment-config';
Expand Down Expand Up @@ -31,6 +31,13 @@ export interface ImportedDeploymentGroupBaseProps {
* @default Either deploymentGroupName or deploymentGroupArn is required
*/
readonly deploymentGroupName: string;

/**
* The ID of the CodeDeploy Deployment Group.
*
* @default - the ID will be constructed from the application name and deployment group name
*/
readonly deploymentGroupId?: string;
}

/**
Expand All @@ -42,6 +49,7 @@ export class ImportedDeploymentGroupBase extends Resource {
public static readonly PROPERTY_INJECTION_ID: string = 'aws-cdk-lib.aws-codedeploy.ImportedDeploymentGroupBase';
public readonly deploymentGroupName: string;
public readonly deploymentGroupArn: string;
private readonly _deploymentGroupId?: string;

constructor(scope: Construct, id: string, props: ImportedDeploymentGroupBaseProps) {
const deploymentGroupName = props.deploymentGroupName;
Expand All @@ -60,6 +68,16 @@ export class ImportedDeploymentGroupBase extends Resource {
addConstructMetadata(this, props);
this.deploymentGroupName = deploymentGroupName;
this.deploymentGroupArn = deploymentGroupArn;
this._deploymentGroupId = props.deploymentGroupId;
}

public get deploymentGroupRef() {
if (!this._deploymentGroupId) {
throw new ValidationError(`Cannot access deploymentGroupId for imported deployment group '${this.node.path}'. Please provide the 'deploymentGroupId' property when importing the deployment group.`, this);
}
return {
deploymentGroupId: this._deploymentGroupId,
};
}

/**
Expand Down Expand Up @@ -113,6 +131,12 @@ export class DeploymentGroupBase extends Resource {
*/
public readonly deploymentGroupArn!: string;

/**
* The ID of the Deployment Group.
* @internal
*/
private readonly _deploymentGroupId!: string;

/**
* The service Role of this Deployment Group.
*
Expand Down Expand Up @@ -166,5 +190,12 @@ export class DeploymentGroupBase extends Resource {
resourceName: `${application.applicationName}/${this.physicalName}`,
arnFormat: ArnFormat.COLON_RESOURCE_NAME,
});
(this as any)._deploymentGroupId = resource.attrId;
}

public get deploymentGroupRef() {
return {
deploymentGroupId: this._deploymentGroupId,
};
}
}
21 changes: 20 additions & 1 deletion packages/aws-cdk-lib/aws-codedeploy/lib/server/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Construct } from 'constructs';
import { ArnFormat, IResource, Resource, Stack, Arn } from '../../../core';
import { addConstructMetadata } from '../../../core/lib/metadata-resource';
import { propertyInjectable } from '../../../core/lib/prop-injectable';
import { IApplicationRef } from '../../../interfaces/generated/aws-codedeploy-interfaces.generated';
import { CfnApplication } from '../codedeploy.generated';
import { arnForApplication, validateName } from '../private/utils';

Expand All @@ -15,7 +16,7 @@ import { arnForApplication, validateName } from '../private/utils';
* or one defined in a different CDK Stack,
* use the `#fromServerApplicationName` method.
*/
export interface IServerApplication extends IResource {
export interface IServerApplication extends IResource, IApplicationRef {
/** @attribute */
readonly applicationArn: string;

Expand Down Expand Up @@ -60,6 +61,12 @@ export class ServerApplication extends Resource implements IServerApplication {
class Import extends Resource implements IServerApplication {
public readonly applicationArn = arnForApplication(Stack.of(scope), serverApplicationName);
public readonly applicationName = serverApplicationName;

public get applicationRef() {
return {
applicationName: this.applicationName,
};
}
}

return new Import(scope, id);
Expand All @@ -77,12 +84,24 @@ export class ServerApplication extends Resource implements IServerApplication {
return new class extends Resource implements IServerApplication {
public applicationArn = serverApplicationArn;
public applicationName = Arn.split(serverApplicationArn, ArnFormat.COLON_RESOURCE_NAME).resourceName ?? '<invalid arn>';

public get applicationRef() {
return {
applicationName: this.applicationName,
};
}
}(scope, id, { environmentFromArn: serverApplicationArn });
}

public readonly applicationArn: string;
public readonly applicationName: string;

public get applicationRef() {
return {
applicationName: this.applicationName,
};
}

constructor(scope: Construct, id: string, props: ServerApplicationProps = {}) {
super(scope, id, {
physicalName: props.applicationName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import * as cdk from '../../../core';
import { addConstructMetadata, MethodMetadata } from '../../../core/lib/metadata-resource';
import { propertyInjectable } from '../../../core/lib/prop-injectable';
import { CODEDEPLOY_REMOVE_ALARMS_FROM_DEPLOYMENT_GROUP } from '../../../cx-api';
import { IDeploymentGroupRef } from '../../../interfaces/generated/aws-codedeploy-interfaces.generated';
import { CfnDeploymentGroup } from '../codedeploy.generated';
import { ImportedDeploymentGroupBase, DeploymentGroupBase } from '../private/base-deployment-group';
import { renderAlarmConfiguration, renderAutoRollbackConfiguration } from '../private/utils';
import { AutoRollbackConfig } from '../rollback-config';

export interface IServerDeploymentGroup extends cdk.IResource {
export interface IServerDeploymentGroup extends cdk.IResource, IDeploymentGroupRef {
readonly application: IServerApplication;
readonly role?: iam.IRole;
/**
Expand Down Expand Up @@ -56,6 +57,13 @@ export interface ServerDeploymentGroupAttributes {
* @default ServerDeploymentConfig#OneAtATime
*/
readonly deploymentConfig?: IServerDeploymentConfig;

/**
* The ID of the CodeDeploy Deployment Group.
*
* @default - the ID will be constructed from the application name and deployment group name
*/
readonly deploymentGroupId?: string;
}

@propertyInjectable
Expand All @@ -71,6 +79,7 @@ class ImportedServerDeploymentGroup extends ImportedDeploymentGroupBase implemen
super(scope, id, {
application: props.application,
deploymentGroupName: props.deploymentGroupName,
deploymentGroupId: props.deploymentGroupId,
});
// Enhanced CDK Analytics Telemetry
addConstructMetadata(this, props);
Expand Down
Loading