Skip to content

Commit 3853728

Browse files
authored
fix(ec2): launch template missing tags (#21445)
fixes #21440 Tags for `instance` and `volume` were forwarded but tags on the `launch-template` itself were missing ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent c019785 commit 3853728

File tree

3 files changed

+84
-2
lines changed

3 files changed

+84
-2
lines changed

Diff for: packages/@aws-cdk/aws-autoscaling/test/asg-lt.integ.snapshot/aws-cdk-asg-integ.template.json

+24-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,18 @@
2828
]
2929
}
3030
]
31-
}
31+
},
32+
"TagSpecifications": [
33+
{
34+
"ResourceType": "launch-template",
35+
"Tags": [
36+
{
37+
"Key": "Name",
38+
"Value": "aws-cdk-asg-integ/MainLT"
39+
}
40+
]
41+
}
42+
]
3243
}
3344
},
3445
"T4gLT8FF7D308": {
@@ -59,7 +70,18 @@
5970
]
6071
}
6172
]
62-
}
73+
},
74+
"TagSpecifications": [
75+
{
76+
"ResourceType": "launch-template",
77+
"Tags": [
78+
{
79+
"Key": "Name",
80+
"Value": "aws-cdk-asg-integ/T4gLT"
81+
}
82+
]
83+
}
84+
]
6385
}
6486
},
6587
"VPCB9E5F0B4": {

Diff for: packages/@aws-cdk/aws-ec2/lib/launch-template.ts

+23
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ export class LaunchTemplate extends Resource implements ILaunchTemplate, iam.IGr
563563
}
564564

565565
this.tags = new TagManager(TagType.KEY_VALUE, 'AWS::EC2::LaunchTemplate');
566+
566567
const tagsToken = Lazy.any({
567568
produce: () => {
568569
if (this.tags.hasTags()) {
@@ -588,6 +589,27 @@ export class LaunchTemplate extends Resource implements ILaunchTemplate, iam.IGr
588589
},
589590
});
590591

592+
const ltTagsToken = Lazy.any({
593+
produce: () => {
594+
if (this.tags.hasTags()) {
595+
const renderedTags = this.tags.renderTags();
596+
const lowerCaseRenderedTags = renderedTags.map( (tag: { [key: string]: string}) => {
597+
return {
598+
key: tag.Key,
599+
value: tag.Value,
600+
};
601+
});
602+
return [
603+
{
604+
resourceType: 'launch-template',
605+
tags: lowerCaseRenderedTags,
606+
},
607+
];
608+
}
609+
return undefined;
610+
},
611+
});
612+
591613
const resource = new CfnLaunchTemplate(this, 'Resource', {
592614
launchTemplateName: props?.launchTemplateName,
593615
launchTemplateData: {
@@ -655,6 +677,7 @@ export class LaunchTemplate extends Resource implements ILaunchTemplate, iam.IGr
655677
// placement: undefined,
656678

657679
},
680+
tagSpecifications: ltTagsToken,
658681
});
659682

660683
Tags.of(this).add(NAME_TAG, this.node.path);

Diff for: packages/@aws-cdk/aws-ec2/test/launch-template.test.ts

+37
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ describe('LaunchTemplate', () => {
7474
},
7575
],
7676
},
77+
TagSpecifications: [
78+
{
79+
ResourceType: 'launch-template',
80+
Tags: [
81+
{
82+
Key: 'Name',
83+
Value: 'Default/Template',
84+
},
85+
],
86+
},
87+
],
7788
});
7889
Template.fromStack(stack).resourceCountIs('AWS::IAM::InstanceProfile', 0);
7990
expect(() => { template.grantPrincipal; }).toThrow();
@@ -248,6 +259,17 @@ describe('LaunchTemplate', () => {
248259
},
249260
],
250261
},
262+
TagSpecifications: [
263+
{
264+
ResourceType: 'launch-template',
265+
Tags: [
266+
{
267+
Key: 'Name',
268+
Value: 'Default/Template',
269+
},
270+
],
271+
},
272+
],
251273
});
252274
expect(template.role).toBeDefined();
253275
expect(template.grantPrincipal).toBeDefined();
@@ -533,6 +555,21 @@ describe('LaunchTemplate', () => {
533555
},
534556
],
535557
},
558+
TagSpecifications: [
559+
{
560+
ResourceType: 'launch-template',
561+
Tags: [
562+
{
563+
Key: 'Name',
564+
Value: 'Default/Template',
565+
},
566+
{
567+
Key: 'TestKey',
568+
Value: 'TestValue',
569+
},
570+
],
571+
},
572+
],
536573
});
537574
});
538575

0 commit comments

Comments
 (0)