Skip to content

Commit

Permalink
chore(aspects): set priorities for existing aspects in CDK (#32333)
Browse files Browse the repository at this point in the history
Follow-up to #32097 

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
sumupitchayan authored Dec 2, 2024
1 parent 20edc7f commit f091714
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class ApplicationAssociator extends Construct {
this.associateCrossAccountStacks = targetBindResult.associateCrossAccountStacks;
cdk.Aspects.of(scope).add(new CheckedStageStackAssociator(this, {
associateCrossAccountStacks: this.associateCrossAccountStacks,
}));
}), { priority: cdk.AspectPriority.MUTATING });
}

/**
Expand All @@ -61,7 +61,7 @@ export class ApplicationAssociator extends Construct {
this.associatedStages.add(stage);
cdk.Aspects.of(stage).add(new CheckedStageStackAssociator(this, {
associateCrossAccountStacks: this.associateCrossAccountStacks,
}));
}), { priority: cdk.AspectPriority.MUTATING });
return stage;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Aspects, CfnOutput, CustomResource, Lazy, Token } from 'aws-cdk-lib';
import { AspectPriority, Aspects, CfnOutput, CustomResource, Lazy, Token } from 'aws-cdk-lib';
import { Construct, IConstruct } from 'constructs';
import { ApiCallBase, IApiCall } from './api-call-base';
import { ExpectedResult } from './common';
Expand Down Expand Up @@ -51,7 +51,7 @@ export class HttpApiCall extends ApiCallBase {
}
}
},
});
}, { priority: AspectPriority.MUTATING });
}

public assertAtPath(_path: string, _expected: ExpectedResult): IApiCall {
Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/integ-tests-alpha/lib/assertions/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ArnFormat, CfnResource, CustomResource, Lazy, Stack, Aspects, CfnOutput } from 'aws-cdk-lib/core';
import { ArnFormat, CfnResource, CustomResource, Lazy, Stack, Aspects, CfnOutput, AspectPriority } from 'aws-cdk-lib/core';
import { Construct, IConstruct } from 'constructs';
import { ApiCallBase, IApiCall } from './api-call-base';
import { ExpectedResult } from './common';
Expand Down Expand Up @@ -125,7 +125,7 @@ export class AwsApiCall extends ApiCallBase {
}
}
},
});
}, { priority: AspectPriority.MUTATING });
}

public assertAtPath(path: string, expected: ExpectedResult): IApiCall {
Expand Down Expand Up @@ -281,6 +281,6 @@ export class LambdaInvokeFunction extends AwsApiCall {
})]);
}
},
});
}, { priority: AspectPriority.MUTATING });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import * as iam from '../../aws-iam';
import * as sns from '../../aws-sns';
import {
Annotations,
AspectPriority,
Aspects,
Aws,
CfnAutoScalingRollingUpdate, CfnCreationPolicy, CfnUpdatePolicy,
Expand Down Expand Up @@ -1573,7 +1574,7 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements
this.spotPrice = props.spotPrice;

if (props.requireImdsv2) {
Aspects.of(this).add(new AutoScalingGroupRequireImdsv2Aspect());
Aspects.of(this).add(new AutoScalingGroupRequireImdsv2Aspect(), { priority: AspectPriority.MUTATING });
}

this.node.addValidation({ validate: () => this.validateTargetGroup() });
Expand Down
4 changes: 2 additions & 2 deletions packages/aws-cdk-lib/aws-backup/lib/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BackupableResourcesCollector } from './backupable-resources-collector';
import { IBackupPlan } from './plan';
import { BackupResource, TagOperation } from './resource';
import * as iam from '../../aws-iam';
import { Lazy, Resource, Aspects } from '../../core';
import { Lazy, Resource, Aspects, AspectPriority } from '../../core';

/**
* Options for a BackupSelection
Expand Down Expand Up @@ -140,7 +140,7 @@ export class BackupSelection extends Resource implements iam.IGrantable {
}

if (resource.construct) {
Aspects.of(resource.construct).add(this.backupableResourcesCollector);
Aspects.of(resource.construct).add(this.backupableResourcesCollector, { priority: AspectPriority.MUTATING });
// Cannot push `this.backupableResourcesCollector.resources` to
// `this.resources` here because it has not been evaluated yet.
// Will be concatenated to `this.resources` in a `Lazy.list`
Expand Down
4 changes: 2 additions & 2 deletions packages/aws-cdk-lib/aws-ec2/lib/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { UserData } from './user-data';
import { BlockDevice } from './volume';
import { IVpc, Subnet, SubnetSelection } from './vpc';
import * as iam from '../../aws-iam';
import { Annotations, Aspects, Duration, FeatureFlags, Fn, IResource, Lazy, Resource, Stack, Tags, Token } from '../../core';
import { Annotations, AspectPriority, Aspects, Duration, FeatureFlags, Fn, IResource, Lazy, Resource, Stack, Tags, Token } from '../../core';
import { md5hash } from '../../core/lib/helpers-internal';
import * as cxapi from '../../cx-api';

Expand Down Expand Up @@ -669,7 +669,7 @@ export class Instance extends Resource implements IInstance {
}));

if (props.requireImdsv2) {
Aspects.of(this).add(new InstanceRequireImdsv2Aspect());
Aspects.of(this).add(new InstanceRequireImdsv2Aspect(), { priority: AspectPriority.MUTATING });
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/aws-cdk-lib/aws-ecs/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { IKey } from '../../aws-kms';
import * as logs from '../../aws-logs';
import * as s3 from '../../aws-s3';
import * as cloudmap from '../../aws-servicediscovery';
import { Aws, Duration, IResource, Resource, Stack, Aspects, ArnFormat, IAspect, Token, Names } from '../../core';
import { Aws, Duration, IResource, Resource, Stack, Aspects, ArnFormat, IAspect, Token, Names, AspectPriority } from '../../core';

const CLUSTER_SYMBOL = Symbol.for('@aws-cdk/aws-ecs/lib/cluster.Cluster');

Expand Down Expand Up @@ -282,7 +282,7 @@ export class Cluster extends Resource implements ICluster {
// since it's harmless, but we'd prefer not to add unexpected new
// resources to the stack which could surprise users working with
// brown-field CDK apps and stacks.
Aspects.of(this).add(new MaybeCreateCapacityProviderAssociations(this, id));
Aspects.of(this).add(new MaybeCreateCapacityProviderAssociations(this, id), { priority: AspectPriority.MUTATING });
}

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/aws-cdk-lib/aws-iam/lib/permissions-boundary.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IConstruct } from 'constructs';
import { CfnRole, CfnUser } from './iam.generated';
import { IManagedPolicy } from './managed-policy';
import { Aspects, CfnResource } from '../../core';
import { AspectPriority, Aspects, CfnResource } from '../../core';

/**
* Modify the Permissions Boundaries of Users and Roles in a construct tree
Expand Down Expand Up @@ -40,7 +40,7 @@ export class PermissionsBoundary {
node.addPropertyOverride('PermissionsBoundary', boundaryPolicy.managedPolicyArn);
}
},
});
}, { priority: AspectPriority.MUTATING });
}

/**
Expand All @@ -56,6 +56,6 @@ export class PermissionsBoundary {
node.addPropertyDeletionOverride('PermissionsBoundary');
}
},
});
}, { priority: AspectPriority.MUTATING });
}
}
4 changes: 2 additions & 2 deletions packages/aws-cdk-lib/aws-iam/lib/role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ImportedRole } from './private/imported-role';
import { MutatingPolicyDocumentAdapter } from './private/policydoc-adapter';
import { PrecreatedRole } from './private/precreated-role';
import { AttachedPolicies, UniqueStringSet } from './private/util';
import { ArnFormat, Duration, Resource, Stack, Token, TokenComparison, Aspects, Annotations, RemovalPolicy } from '../../core';
import { ArnFormat, Duration, Resource, Stack, Token, TokenComparison, Aspects, Annotations, RemovalPolicy, AspectPriority } from '../../core';
import { getCustomizeRolesConfig, getPrecreatedRoleConfig, CUSTOMIZE_ROLES_CONTEXT_KEY, CustomizeRoleConfig } from '../../core/lib/helpers-internal';

const MAX_INLINE_SIZE = 10000;
Expand Down Expand Up @@ -493,7 +493,7 @@ export class Role extends Resource implements IRole {
this.splitLargePolicy();
}
},
});
}, { priority: AspectPriority.MUTATING });
}

this.policyFragment = new ArnPrincipal(this.roleArn).policyFragment;
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-cdk-lib/aws-servicecatalog/lib/portfolio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ export class Portfolio extends PortfolioBase {
(c as Portfolio).addBucketPermissionsToSharedAccounts();
};
},
});
}, { priority: cdk.AspectPriority.MUTATING });
}

protected generateUniqueHash(value: string): string {
Expand Down
4 changes: 2 additions & 2 deletions packages/aws-cdk-lib/core/lib/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IConstruct, Construct, Node } from 'constructs';
import { Annotations } from './annotations';
import { App } from './app';
import { Arn, ArnComponents, ArnFormat } from './arn';
import { Aspects } from './aspect';
import { AspectPriority, Aspects } from './aspect';
import { DockerImageAssetLocation, DockerImageAssetSource, FileAssetLocation, FileAssetSource } from './assets';
import { CfnElement } from './cfn-element';
import { Fn } from './cfn-fn';
Expand Down Expand Up @@ -583,7 +583,7 @@ export class Stack extends Construct implements ITaggable {
node.addPropertyOverride('PermissionsBoundary', permissionsBoundaryArn);
}
},
});
}, { priority: AspectPriority.MUTATING });

}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/aws-cdk-lib/core/lib/tag-aspect.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Construct, IConstruct } from 'constructs';
import { Annotations } from './annotations';
import { IAspect, Aspects } from './aspect';
import { IAspect, Aspects, AspectPriority } from './aspect';
import { ITaggable, ITaggableV2, TagManager } from './tag-manager';

/**
Expand Down Expand Up @@ -161,14 +161,14 @@ export class Tags {
* add tags to the node of a construct and all its the taggable children
*/
public add(key: string, value: string, props: TagProps = {}) {
Aspects.of(this.scope).add(new Tag(key, value, props));
Aspects.of(this.scope).add(new Tag(key, value, props)), { priority: AspectPriority.MUTATING };
}

/**
* remove tags to the node of a construct and all its the taggable children
*/
public remove(key: string, props: TagProps = {}) {
Aspects.of(this.scope).add(new RemoveTag(key, props));
Aspects.of(this.scope).add(new RemoveTag(key, props), { priority: AspectPriority.MUTATING });
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IConstruct, MetadataEntry } from 'constructs';
import * as cloudformation from '../../../aws-cloudformation';
import * as lambda from '../../../aws-lambda';
import * as logs from '../../../aws-logs';
import { Aspects, IAspect, RemovalPolicy } from '../../../core/lib';
import { AspectPriority, Aspects, IAspect, RemovalPolicy } from '../../../core/lib';

/* This is duplicated in @aws-cdk/custom-resource-handlers/lib/custom-resources-framework/config.ts */
export const CUSTOM_RESOURCE_PROVIDER = 'aws:cdk:is-custom-resource-handler-customResourceProvider';
Expand Down Expand Up @@ -32,7 +32,7 @@ export class CustomResourceConfig {
* This feature is currently experimental.
*/
public addLogRetentionLifetime(rentention: logs.RetentionDays) {
Aspects.of(this.scope).add(new CustomResourceLogRetention(rentention));
Aspects.of(this.scope).add(new CustomResourceLogRetention(rentention), { priority: AspectPriority.MUTATING });
}

/**
Expand All @@ -41,7 +41,7 @@ export class CustomResourceConfig {
* This feature is currently experimental.
*/
public addRemovalPolicy(removalPolicy: RemovalPolicy) {
Aspects.of(this.scope).add(new CustomResourceRemovalPolicy(removalPolicy));
Aspects.of(this.scope).add(new CustomResourceRemovalPolicy(removalPolicy), { priority: AspectPriority.MUTATING });
}

/**
Expand All @@ -50,7 +50,7 @@ export class CustomResourceConfig {
* This feature is currently experimental.
*/
public addLambdaRuntime(lambdaRuntime: lambda.Runtime) {
Aspects.of(this.scope).add(new CustomResourceLambdaRuntime(lambdaRuntime));
Aspects.of(this.scope).add(new CustomResourceLambdaRuntime(lambdaRuntime), { priority: AspectPriority.MUTATING });
}

}
Expand Down
4 changes: 2 additions & 2 deletions packages/aws-cdk-lib/pipelines/lib/main/pipeline-base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Construct } from 'constructs';
import { Aspects, Stage } from '../../../core';
import { AspectPriority, Aspects, Stage } from '../../../core';
import { AddStageOpts as StageOptions, WaveOptions, Wave, IFileSetProducer, ShellStep, FileSet } from '../blueprint';

const PIPELINE_SYMBOL = Symbol.for('@aws-cdk/pipelines.PipelineBase');
Expand Down Expand Up @@ -79,7 +79,7 @@ export abstract class PipelineBase extends Construct {
this.waves = [];
this.cloudAssemblyFileSet = props.synth.primaryOutput;

Aspects.of(this).add({ visit: () => this.buildJustInTime() });
Aspects.of(this).add({ visit: () => this.buildJustInTime() }, { priority: AspectPriority.MUTATING });
}

/**
Expand Down

0 comments on commit f091714

Please sign in to comment.