Skip to content

Commit 642c8a6

Browse files
moofish32Elad Ben-Israel
authored andcommitted
fix(cdk): move apply() from Construct to ConstructNode (#1738)
This change moves the aspect `apply()` function from the `Construct` to the `ConstructNode`. All other functionality remains the same. BREAKING CHANGE: Tag aspects use this feature and any consumers of this implementation must change from `myConstruct.apply( ... )` to `myConstruct.node.apply( ... )`. fixes #1732
1 parent 49080c6 commit 642c8a6

File tree

14 files changed

+50
-51
lines changed

14 files changed

+50
-51
lines changed

packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export class AutoScalingGroup extends cdk.Construct implements IAutoScalingGroup
230230
});
231231
this.connections = new ec2.Connections({ securityGroups: [this.securityGroup] });
232232
this.securityGroups.push(this.securityGroup);
233-
this.apply(new cdk.Tag(NAME_TAG, this.node.path));
233+
this.node.apply(new cdk.Tag(NAME_TAG, this.node.path));
234234

235235
this.role = props.role || new iam.Role(this, 'InstanceRole', {
236236
assumedBy: new iam.ServicePrincipal('ec2.amazonaws.com')

packages/@aws-cdk/aws-autoscaling/test/test.auto-scaling-group.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ export = {
380380
pauseTimeSec: 345
381381
},
382382
});
383-
asg.apply( new cdk.Tag('superfood', 'acai'));
384-
asg.apply( new cdk.Tag('notsuper', 'caramel', { applyToLaunchedInstances: false }));
383+
asg.node.apply(new cdk.Tag('superfood', 'acai'));
384+
asg.node.apply(new cdk.Tag('notsuper', 'caramel', { applyToLaunchedInstances: false }));
385385

386386
// THEN
387387
expect(stack).to(haveResource("AWS::AutoScaling::AutoScalingGroup", {

packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.ondemand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const tableWithGlobalAndLocalSecondaryIndex = new Table(stack, TABLE_WITH_GLOBAL
5252
ttlAttributeName: 'timeToLive'
5353
});
5454

55-
tableWithGlobalAndLocalSecondaryIndex.apply(new Tag('Environment', 'Production'));
55+
tableWithGlobalAndLocalSecondaryIndex.node.apply(new Tag('Environment', 'Production'));
5656

5757
tableWithGlobalAndLocalSecondaryIndex.addPartitionKey(TABLE_PARTITION_KEY);
5858
tableWithGlobalAndLocalSecondaryIndex.addSortKey(TABLE_SORT_KEY);

packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const tableWithGlobalAndLocalSecondaryIndex = new Table(stack, TABLE_WITH_GLOBAL
5151
ttlAttributeName: 'timeToLive'
5252
});
5353

54-
tableWithGlobalAndLocalSecondaryIndex.apply(new Tag('Environment', 'Production'));
54+
tableWithGlobalAndLocalSecondaryIndex.node.apply(new Tag('Environment', 'Production'));
5555
tableWithGlobalAndLocalSecondaryIndex.addPartitionKey(TABLE_PARTITION_KEY);
5656
tableWithGlobalAndLocalSecondaryIndex.addSortKey(TABLE_SORT_KEY);
5757
tableWithGlobalAndLocalSecondaryIndex.addGlobalSecondaryIndex({

packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ export = {
317317
});
318318
table.addPartitionKey(TABLE_PARTITION_KEY);
319319
table.addSortKey(TABLE_SORT_KEY);
320-
table.apply(new Tag('Environment', 'Production'));
320+
table.node.apply(new Tag('Environment', 'Production'));
321321

322322
expect(stack).to(haveResource('AWS::DynamoDB::Table',
323323
{

packages/@aws-cdk/aws-ec2/lib/vpc.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ export class VpcNetwork extends VpcNetworkBase {
299299
instanceTenancy,
300300
});
301301

302-
this.apply(new cdk.Tag(NAME_TAG, this.node.path));
302+
this.node.apply(new cdk.Tag(NAME_TAG, this.node.path));
303303

304304
this.availabilityZones = new cdk.AvailabilityZoneProvider(this).availabilityZones;
305305
this.availabilityZones.sort();
@@ -452,8 +452,8 @@ export class VpcNetwork extends VpcNetworkBase {
452452

453453
// These values will be used to recover the config upon provider import
454454
const includeResourceTypes = [CfnSubnet.resourceTypeName];
455-
subnet.apply(new cdk.Tag(SUBNETNAME_TAG, subnetConfig.name, {includeResourceTypes}));
456-
subnet.apply(new cdk.Tag(SUBNETTYPE_TAG, subnetTypeTagValue(subnetConfig.subnetType), {includeResourceTypes}));
455+
subnet.node.apply(new cdk.Tag(SUBNETNAME_TAG, subnetConfig.name, {includeResourceTypes}));
456+
subnet.node.apply(new cdk.Tag(SUBNETTYPE_TAG, subnetTypeTagValue(subnetConfig.subnetType), {includeResourceTypes}));
457457
});
458458
}
459459
}
@@ -529,7 +529,7 @@ export class VpcSubnet extends cdk.Construct implements IVpcSubnet {
529529

530530
constructor(scope: cdk.Construct, id: string, props: VpcSubnetProps) {
531531
super(scope, id);
532-
this.apply(new cdk.Tag(NAME_TAG, this.node.path));
532+
this.node.apply(new cdk.Tag(NAME_TAG, this.node.path));
533533

534534
this.availabilityZone = props.availabilityZone;
535535
const subnet = new CfnSubnet(this, 'Subnet', {

packages/@aws-cdk/aws-ec2/test/test.vpc.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ export = {
349349

350350
const vpc = new VpcNetwork(stack, 'TheVPC');
351351
// overwrite to set propagate
352-
vpc.apply(new Tag('BusinessUnit', 'Marketing', {includeResourceTypes: [CfnVPC.resourceTypeName]}));
353-
vpc.apply(new Tag('VpcType', 'Good'));
352+
vpc.node.apply(new Tag('BusinessUnit', 'Marketing', {includeResourceTypes: [CfnVPC.resourceTypeName]}));
353+
vpc.node.apply(new Tag('VpcType', 'Good'));
354354
expect(stack).to(haveResource("AWS::EC2::VPC", hasTags(toCfnTags(allTags))));
355355
const taggables = ['Subnet', 'InternetGateway', 'NatGateway', 'RouteTable'];
356356
const propTags = toCfnTags(tags);
@@ -381,7 +381,7 @@ export = {
381381
const vpc = new VpcNetwork(stack, 'TheVPC');
382382
const tag = {Key: 'Late', Value: 'Adder'};
383383
expect(stack).notTo(haveResource('AWS::EC2::VPC', hasTags([tag])));
384-
vpc.apply(new Tag(tag.Key, tag.Value));
384+
vpc.node.apply(new Tag(tag.Key, tag.Value));
385385
expect(stack).to(haveResource('AWS::EC2::VPC', hasTags([tag])));
386386
test.done();
387387
},

packages/@aws-cdk/aws-eks/lib/cluster.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ export class Cluster extends ClusterBase {
247247
autoScalingGroup.role.attachManagedPolicy(new iam.AwsManagedPolicy('AmazonEC2ContainerRegistryReadOnly', this).policyArn);
248248

249249
// EKS Required Tags
250-
autoScalingGroup.apply(new cdk.Tag(`kubernetes.io/cluster/${this.clusterName}`, 'owned', { applyToLaunchedInstances: true }));
250+
autoScalingGroup.node.apply(new cdk.Tag(`kubernetes.io/cluster/${this.clusterName}`, 'owned', { applyToLaunchedInstances: true }));
251251

252252
// Create an Output for the Instance Role ARN (need to paste it into aws-auth-cm.yaml)
253253
new cdk.Output(autoScalingGroup, 'InstanceRoleARN', {
@@ -273,7 +273,7 @@ export class Cluster extends ClusterBase {
273273
return;
274274
}
275275

276-
subnet.apply(new cdk.Tag("kubernetes.io/role/internal-elb", "1"));
276+
subnet.node.apply(new cdk.Tag("kubernetes.io/role/internal-elb", "1"));
277277
}
278278
}
279279
}
@@ -339,4 +339,4 @@ function flatMap<T, U>(xs: T[], f: (x: T) => U[]): U[] {
339339
ret.push(...f(x));
340340
}
341341
return ret;
342-
}
342+
}

packages/@aws-cdk/aws-kms/test/test.key.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ export = {
147147
p.addAwsPrincipal('arn');
148148
key.addToResourcePolicy(p);
149149

150-
key.apply(new Tag('tag1', 'value1'));
151-
key.apply(new Tag('tag2', 'value2'));
152-
key.apply(new Tag('tag3', ''));
150+
key.node.apply(new Tag('tag1', 'value1'));
151+
key.node.apply(new Tag('tag2', 'value2'));
152+
key.node.apply(new Tag('tag3', ''));
153153

154154
expect(stack).to(exactlyMatchTemplate({
155155
Resources: {

packages/@aws-cdk/aws-s3/test/test.notifications.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export = {
4444
},
4545
'when notification are added, you can tag the lambda'(test: Test) {
4646
const stack = new cdk.Stack();
47-
stack.apply(new cdk.Tag('Lambda', 'AreTagged'));
47+
stack.node.apply(new cdk.Tag('Lambda', 'AreTagged'));
4848

4949
const bucket = new s3.Bucket(stack, 'MyBucket');
5050

0 commit comments

Comments
 (0)