diff --git a/packages/aws-cdk-lib/aws-xray/test/xray.test.ts b/packages/aws-cdk-lib/aws-xray/test/xray.test.ts new file mode 100644 index 0000000000000..6f4df4fc6f0dd --- /dev/null +++ b/packages/aws-cdk-lib/aws-xray/test/xray.test.ts @@ -0,0 +1,41 @@ +import { Match, Template } from '../../assertions'; +import * as iam from '../../aws-iam'; +import * as kms from '../../aws-kms'; +import { CfnParameter, Duration, Stack, App, Token, Tags } from '../../core'; +import * as xray from '../lib'; + +/* eslint-disable quote-props */ + +test('able to add tags to XRay CfnGroup', () => { + const stack = new Stack(); + new xray.CfnGroup(stack, 'Group', { + groupName: 'GroupName', + tags: [{ + key: 'Key', + value: 'Value', + }], + }); + + Template.fromStack(stack).hasResourceProperties('AWS::XRay::Group', { + Tags: [{ + Key: 'Key', + Value: 'Value', + }], + }); +}); + +test('able to add tags through Tags.of()... to XRay CfnGroup', () => { + const stack = new Stack(); + new xray.CfnGroup(stack, 'Group', { + groupName: 'GroupName', + }); + + Tags.of(stack).add('Key', 'Value'); + + Template.fromStack(stack).hasResourceProperties('AWS::XRay::Group', { + Tags: [{ + Key: 'Key', + Value: 'Value', + }], + }); +}); diff --git a/tools/@aws-cdk/spec2cdk/lib/cdk/resource-decider.ts b/tools/@aws-cdk/spec2cdk/lib/cdk/resource-decider.ts index 2db62bb3d0b4a..7b981cacb8fd7 100644 --- a/tools/@aws-cdk/spec2cdk/lib/cdk/resource-decider.ts +++ b/tools/@aws-cdk/spec2cdk/lib/cdk/resource-decider.ts @@ -179,7 +179,7 @@ export class ResourceDecider { private handleTagPropertyModern(cfnName: string, prop: Property, variant: TagVariant) { const originalName = propertyNameFromCloudFormation(cfnName); - const originalType = this.converter.typeFromProperty(prop); + const originalType = this.converter.typeFromPropertyForModernTags(prop); this.propsProperties.push({ propertySpec: { diff --git a/tools/@aws-cdk/spec2cdk/lib/cdk/type-converter.ts b/tools/@aws-cdk/spec2cdk/lib/cdk/type-converter.ts index df3a215e503e5..5accddfe15da2 100644 --- a/tools/@aws-cdk/spec2cdk/lib/cdk/type-converter.ts +++ b/tools/@aws-cdk/spec2cdk/lib/cdk/type-converter.ts @@ -96,6 +96,16 @@ export class TypeConverter { return this.typeFromSpecType(this.typeHistoryFromProperty(property)[0]); } + /** + * Return the appropriate typewriter type for a servicespec type for modern tags + * Unlike typeFromProperty, we want to default to use the newest type instead. + */ + public typeFromPropertyForModernTags(property: Property): Type { + // For backwards compatibility reasons we always have to use the original type + const types = this.typeHistoryFromProperty(property); + return this.typeFromSpecType(types[types.length - 1]); + } + /** * Return the full type history for a servicespec property */