Skip to content

Commit 96767d7

Browse files
jungseokleeElad Ben-Israel
authored and
Elad Ben-Israel
committed
fix(cdk): fix TagManager to evaluate to undefined if no tags are included (#882)
It is unnecessary to add "Tags" field to CloudFormation template unless tags are specified. Therefore, this patch fixes TagManager to evaluate to undefined if there are no tags included.
1 parent 56f0b4e commit 96767d7

File tree

11 files changed

+35
-68
lines changed

11 files changed

+35
-68
lines changed

Diff for: packages/@aws-cdk/aws-autoscaling/test/integ.asg-w-classic-loadbalancer.expected.json

-1
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,6 @@
589589
"ToPort": 80
590590
}
591591
],
592-
"Tags": [],
593592
"VpcId": {
594593
"Ref": "VPCB9E5F0B4"
595594
}

Diff for: packages/@aws-cdk/aws-autoscaling/test/integ.asg-w-elbv2.expected.json

-1
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,6 @@
476476
"ToPort": 80
477477
}
478478
],
479-
"Tags": [],
480479
"VpcId": {
481480
"Ref": "VPCB9E5F0B4"
482481
}

Diff for: packages/@aws-cdk/aws-codedeploy/test/integ.deployment-group.expected.json

-1
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,6 @@
674674
"ToPort": 80
675675
}
676676
],
677-
"Tags": [],
678677
"VpcId": {
679678
"Ref": "VPCB9E5F0B4"
680679
}

Diff for: packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.expected.json

+3-6
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
}
2121
],
2222
"GlobalSecondaryIndexes": [],
23-
"LocalSecondaryIndexes": [],
24-
"Tags": []
23+
"LocalSecondaryIndexes": []
2524
}
2625
},
2726
"TableWithGlobalAndLocalSecondaryIndexBC540710": {
@@ -313,8 +312,7 @@
313312
}
314313
}
315314
],
316-
"LocalSecondaryIndexes": [],
317-
"Tags": []
315+
"LocalSecondaryIndexes": []
318316
}
319317
},
320318
"TableWithLocalSecondaryIndex4DA3D08F": {
@@ -366,8 +364,7 @@
366364
"ProjectionType": "ALL"
367365
}
368366
}
369-
],
370-
"Tags": []
367+
]
371368
}
372369
}
373370
}

Diff for: packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts

+24-50
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ export = {
8787
KeySchema: [{ AttributeName: 'hashKey', KeyType: 'HASH' }],
8888
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
8989
GlobalSecondaryIndexes: [],
90-
LocalSecondaryIndexes: [],
91-
Tags: []
90+
LocalSecondaryIndexes: []
9291
}
9392
}
9493
}
@@ -119,8 +118,7 @@ export = {
119118
],
120119
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
121120
GlobalSecondaryIndexes: [],
122-
LocalSecondaryIndexes: [],
123-
Tags: []
121+
LocalSecondaryIndexes: []
124122
}
125123
}
126124
}
@@ -151,8 +149,7 @@ export = {
151149
],
152150
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
153151
GlobalSecondaryIndexes: [],
154-
LocalSecondaryIndexes: [],
155-
Tags: []
152+
LocalSecondaryIndexes: []
156153
}
157154
}
158155
}
@@ -183,8 +180,7 @@ export = {
183180
],
184181
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
185182
GlobalSecondaryIndexes: [],
186-
LocalSecondaryIndexes: [],
187-
Tags: []
183+
LocalSecondaryIndexes: []
188184
}
189185
}
190186
}
@@ -215,8 +211,7 @@ export = {
215211
],
216212
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
217213
GlobalSecondaryIndexes: [],
218-
LocalSecondaryIndexes: [],
219-
Tags: []
214+
LocalSecondaryIndexes: []
220215
}
221216
}
222217
}
@@ -247,8 +242,7 @@ export = {
247242
],
248243
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
249244
GlobalSecondaryIndexes: [],
250-
LocalSecondaryIndexes: [],
251-
Tags: []
245+
LocalSecondaryIndexes: []
252246
}
253247
}
254248
}
@@ -286,8 +280,7 @@ export = {
286280
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
287281
GlobalSecondaryIndexes: [],
288282
LocalSecondaryIndexes: [],
289-
TableName: 'MyTable',
290-
Tags: []
283+
TableName: 'MyTable'
291284
}
292285
}
293286
}
@@ -325,8 +318,7 @@ export = {
325318
{ AttributeName: 'sortKey', AttributeType: 'N' }
326319
],
327320
StreamSpecification: { StreamViewType: 'NEW_IMAGE' },
328-
TableName: 'MyTable',
329-
Tags: []
321+
TableName: 'MyTable'
330322
}
331323
}
332324
}
@@ -364,8 +356,7 @@ export = {
364356
{ AttributeName: 'sortKey', AttributeType: 'N' }
365357
],
366358
StreamSpecification: { StreamViewType: 'OLD_IMAGE' },
367-
TableName: 'MyTable',
368-
Tags: []
359+
TableName: 'MyTable'
369360
}
370361
}
371362
}
@@ -462,8 +453,7 @@ export = {
462453
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 }
463454
}
464455
],
465-
LocalSecondaryIndexes: [],
466-
Tags: []
456+
LocalSecondaryIndexes: []
467457
}
468458
}
469459
}
@@ -514,8 +504,7 @@ export = {
514504
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 }
515505
}
516506
],
517-
LocalSecondaryIndexes: [],
518-
Tags: []
507+
LocalSecondaryIndexes: []
519508
}
520509
}
521510
}
@@ -564,8 +553,7 @@ export = {
564553
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 }
565554
}
566555
],
567-
LocalSecondaryIndexes: [],
568-
Tags: []
556+
LocalSecondaryIndexes: []
569557
}
570558
}
571559
}
@@ -618,8 +606,7 @@ export = {
618606
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 }
619607
}
620608
],
621-
LocalSecondaryIndexes: [],
622-
Tags: []
609+
LocalSecondaryIndexes: []
623610
}
624611
}
625612
}
@@ -789,8 +776,7 @@ export = {
789776
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 }
790777
},
791778
],
792-
LocalSecondaryIndexes: [],
793-
Tags: []
779+
LocalSecondaryIndexes: []
794780
}
795781
}
796782
}
@@ -851,8 +837,7 @@ export = {
851837
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 }
852838
}
853839
],
854-
LocalSecondaryIndexes: [],
855-
Tags: []
840+
LocalSecondaryIndexes: []
856841
}
857842
}
858843
}
@@ -897,8 +882,7 @@ export = {
897882
],
898883
Projection: { ProjectionType: 'ALL' },
899884
}
900-
],
901-
Tags: []
885+
]
902886
}
903887
}
904888
}
@@ -944,8 +928,7 @@ export = {
944928
],
945929
Projection: { ProjectionType: 'KEYS_ONLY' },
946930
}
947-
],
948-
Tags: []
931+
]
949932
}
950933
}
951934
}
@@ -994,8 +977,7 @@ export = {
994977
],
995978
Projection: { NonKeyAttributes: ['lsiNonKey0', 'lsiNonKey1'], ProjectionType: 'INCLUDE' },
996979
}
997-
],
998-
Tags: []
980+
]
999981
}
1000982
}
1001983
}
@@ -1100,8 +1082,7 @@ export = {
11001082
AttributeDefinitions:
11011083
[ { AttributeName: 'hashKey', AttributeType: 'S' },
11021084
{ AttributeName: 'sortKey', AttributeType: 'N' } ],
1103-
TableName: 'MyTable',
1104-
Tags: [] } },
1085+
TableName: 'MyTable' } },
11051086
MyTableReadAutoScalingRoleFEE68E49:
11061087
{ Type: 'AWS::IAM::Role',
11071088
Properties:
@@ -1183,8 +1164,7 @@ export = {
11831164
AttributeDefinitions:
11841165
[ { AttributeName: 'hashKey', AttributeType: 'S' },
11851166
{ AttributeName: 'sortKey', AttributeType: 'N' } ],
1186-
TableName: 'MyTable',
1187-
Tags: [] } },
1167+
TableName: 'MyTable' } },
11881168
MyTableReadAutoScalingRoleFEE68E49:
11891169
{ Type: 'AWS::IAM::Role',
11901170
Properties:
@@ -1294,8 +1274,7 @@ export = {
12941274
AttributeDefinitions:
12951275
[ { AttributeName: 'hashKey', AttributeType: 'S' },
12961276
{ AttributeName: 'sortKey', AttributeType: 'N' } ],
1297-
TableName: 'MyTable',
1298-
Tags: [] } },
1277+
TableName: 'MyTable' } },
12991278
MyTableReadAutoScalingRoleFEE68E49:
13001279
{ Type: 'AWS::IAM::Role',
13011280
Properties:
@@ -1373,7 +1352,6 @@ export = {
13731352
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
13741353
GlobalSecondaryIndexes: [],
13751354
LocalSecondaryIndexes: [],
1376-
Tags: [],
13771355
AttributeDefinitions:
13781356
[ { AttributeName: 'hashKey', AttributeType: 'S' },
13791357
{ AttributeName: 'sortKey', AttributeType: 'N' } ] } },
@@ -1581,8 +1559,7 @@ export = {
15811559
AttributeDefinitions:
15821560
[ { AttributeName: 'hashKey', AttributeType: 'S' },
15831561
{ AttributeName: 'sortKey', AttributeType: 'N' } ],
1584-
TableName: 'MyTable',
1585-
Tags: [] } },
1562+
TableName: 'MyTable' } },
15861563
MyTableWriteAutoScalingRoleDF7775DE:
15871564
{ Type: 'AWS::IAM::Role',
15881565
Properties:
@@ -1664,8 +1641,7 @@ export = {
16641641
AttributeDefinitions:
16651642
[ { AttributeName: 'hashKey', AttributeType: 'S' },
16661643
{ AttributeName: 'sortKey', AttributeType: 'N' } ],
1667-
TableName: 'MyTable',
1668-
Tags: [] } },
1644+
TableName: 'MyTable' } },
16691645
MyTableWriteAutoScalingRoleDF7775DE:
16701646
{ Type: 'AWS::IAM::Role',
16711647
Properties:
@@ -1775,8 +1751,7 @@ export = {
17751751
AttributeDefinitions:
17761752
[ { AttributeName: 'hashKey', AttributeType: 'S' },
17771753
{ AttributeName: 'sortKey', AttributeType: 'N' } ],
1778-
TableName: 'MyTable',
1779-
Tags: [] } },
1754+
TableName: 'MyTable' } },
17801755
MyTableWriteAutoScalingRoleDF7775DE:
17811756
{ Type: 'AWS::IAM::Role',
17821757
Properties:
@@ -1854,7 +1829,6 @@ export = {
18541829
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
18551830
GlobalSecondaryIndexes: [],
18561831
LocalSecondaryIndexes: [],
1857-
Tags: [],
18581832
AttributeDefinitions:
18591833
[ { AttributeName: 'hashKey', AttributeType: 'S' },
18601834
{ AttributeName: 'sortKey', AttributeType: 'N' } ] } },

Diff for: packages/@aws-cdk/aws-elasticloadbalancing/test/integ.elb.expected.json

-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@
185185
"ToPort": 80
186186
}
187187
],
188-
"Tags": [],
189188
"VpcId": {
190189
"Ref": "VPCB9E5F0B4"
191190
}

Diff for: packages/@aws-cdk/aws-elasticloadbalancingv2/test/integ.alb.expected.json

-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,6 @@
343343
"ToPort": 80
344344
}
345345
],
346-
"Tags": [],
347346
"VpcId": {
348347
"Ref": "VPCB9E5F0B4"
349348
}

Diff for: packages/@aws-cdk/aws-lambda/test/integ.vpc-lambda.expected.json

-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,6 @@
382382
}
383383
],
384384
"SecurityGroupIngress": [],
385-
"Tags": [],
386385
"VpcId": {
387386
"Ref": "VPCB9E5F0B4"
388387
}

Diff for: packages/@aws-cdk/aws-rds/test/integ.cluster.expected.json

-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,6 @@
382382
"GroupDescription": "RDS security group",
383383
"SecurityGroupEgress": [],
384384
"SecurityGroupIngress": [],
385-
"Tags": [],
386385
"VpcId": {
387386
"Ref": "VPCB9E5F0B4"
388387
}

Diff for: packages/@aws-cdk/cdk/lib/core/tag-manager.ts

+3
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ export class TagManager extends Token {
265265
protected tagFormatResolve(tagGroups: TagGroups): any {
266266
const tags = {...tagGroups.nonStickyTags, ...tagGroups.ancestorTags, ...tagGroups.stickyTags};
267267
for (const key of this.blockedTags) { delete tags[key]; }
268+
if (Object.keys(tags).length === 0) {
269+
return undefined;
270+
}
268271
return Object.keys(tags).map( key => ({key, value: tags[key]}));
269272
}
270273
}

Diff for: packages/@aws-cdk/cdk/test/core/test.tag-manager.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export = {
3535
test.deepEqual(construct.tags.resolve(), tagArray);
3636
}
3737

38-
test.deepEqual(ctagger2.tags.resolve().length, 0);
38+
test.deepEqual(ctagger2.tags.resolve(), undefined);
3939
test.done();
4040
},
4141
'setTag with propagate false tags do not propagate'(test: Test) {
@@ -51,7 +51,7 @@ export = {
5151
ctagger.tags.setTag(tag.key, tag.value, {propagate: false});
5252

5353
for (const construct of [ctagger1, ctagger2]) {
54-
test.deepEqual(construct.tags.resolve().length, 0);
54+
test.deepEqual(construct.tags.resolve(), undefined);
5555
}
5656
test.deepEqual(ctagger.tags.resolve()[0].key, 'Name');
5757
test.deepEqual(ctagger.tags.resolve()[0].value, 'TheCakeIsALie');
@@ -96,7 +96,7 @@ export = {
9696
ctagger.tags.setTag(tag.key, tag.value, {propagate: true});
9797
test.deepEqual(ctagger.tags.resolve(), [tag]);
9898
ctagger.tags.removeTag(tag.key);
99-
test.deepEqual(ctagger.tags.resolve(), []);
99+
test.deepEqual(ctagger.tags.resolve(), undefined);
100100
ctagger.tags.setTag(tag.key, tag.value, {propagate: true});
101101
test.deepEqual(ctagger.tags.resolve(), [tag]);
102102
test.done();
@@ -115,7 +115,7 @@ export = {
115115
ctagger.tags.removeTag('Name');
116116

117117
for (const construct of [ctagger, ctagger1, ctagger2]) {
118-
test.deepEqual(construct.tags.resolve().length, 0);
118+
test.deepEqual(construct.tags.resolve(), undefined);
119119
}
120120
test.done();
121121
},
@@ -127,7 +127,7 @@ export = {
127127
ctagger1.tags.removeTag('Env', {blockPropagate: true});
128128
const result = ctagger.tags.resolve();
129129
test.deepEqual(result, [{key: 'Env', value: 'Dev'}]);
130-
test.deepEqual(ctagger1.tags.resolve(), []);
130+
test.deepEqual(ctagger1.tags.resolve(), undefined);
131131
test.done();
132132
},
133133
'children can override parent propagated tags'(test: Test) {

0 commit comments

Comments
 (0)