Skip to content

Commit 3fb0254

Browse files
authored
fix(spec2cdk): use modern type when building tag type (#29389)
### Issue # (if applicable) Closes #29388 ### Reason for this change Some of the modern tags failed to run `cdk synth` due to type misconfiguration. ### Description of changes Always default to use the latest type for modern tags. ### Description of how you validated changes Fixed for failed resources. ### 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*
1 parent d33caff commit 3fb0254

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { Match, Template } from '../../assertions';
2+
import * as iam from '../../aws-iam';
3+
import * as kms from '../../aws-kms';
4+
import { CfnParameter, Duration, Stack, App, Token, Tags } from '../../core';
5+
import * as xray from '../lib';
6+
7+
/* eslint-disable quote-props */
8+
9+
test('able to add tags to XRay CfnGroup', () => {
10+
const stack = new Stack();
11+
new xray.CfnGroup(stack, 'Group', {
12+
groupName: 'GroupName',
13+
tags: [{
14+
key: 'Key',
15+
value: 'Value',
16+
}],
17+
});
18+
19+
Template.fromStack(stack).hasResourceProperties('AWS::XRay::Group', {
20+
Tags: [{
21+
Key: 'Key',
22+
Value: 'Value',
23+
}],
24+
});
25+
});
26+
27+
test('able to add tags through Tags.of()... to XRay CfnGroup', () => {
28+
const stack = new Stack();
29+
new xray.CfnGroup(stack, 'Group', {
30+
groupName: 'GroupName',
31+
});
32+
33+
Tags.of(stack).add('Key', 'Value');
34+
35+
Template.fromStack(stack).hasResourceProperties('AWS::XRay::Group', {
36+
Tags: [{
37+
Key: 'Key',
38+
Value: 'Value',
39+
}],
40+
});
41+
});

tools/@aws-cdk/spec2cdk/lib/cdk/resource-decider.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export class ResourceDecider {
179179

180180
private handleTagPropertyModern(cfnName: string, prop: Property, variant: TagVariant) {
181181
const originalName = propertyNameFromCloudFormation(cfnName);
182-
const originalType = this.converter.typeFromProperty(prop);
182+
const originalType = this.converter.typeFromPropertyForModernTags(prop);
183183

184184
this.propsProperties.push({
185185
propertySpec: {

tools/@aws-cdk/spec2cdk/lib/cdk/type-converter.ts

+10
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ export class TypeConverter {
9696
return this.typeFromSpecType(this.typeHistoryFromProperty(property)[0]);
9797
}
9898

99+
/**
100+
* Return the appropriate typewriter type for a servicespec type for modern tags
101+
* Unlike typeFromProperty, we want to default to use the newest type instead.
102+
*/
103+
public typeFromPropertyForModernTags(property: Property): Type {
104+
// For backwards compatibility reasons we always have to use the original type
105+
const types = this.typeHistoryFromProperty(property);
106+
return this.typeFromSpecType(types[types.length - 1]);
107+
}
108+
99109
/**
100110
* Return the full type history for a servicespec property
101111
*/

0 commit comments

Comments
 (0)