From fdc2cf9f39c5da9bc28032deade25842876449b4 Mon Sep 17 00:00:00 2001 From: rafaelrcamargo Date: Wed, 29 Nov 2023 23:15:38 -0300 Subject: [PATCH] feat: deprecated keyArn and added aliasArn as the new name for the ARN into the alias L2 construct --- packages/aws-cdk-lib/aws-kms/lib/alias.ts | 15 +++++++++++++++ packages/aws-cdk-lib/aws-kms/test/alias.test.ts | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/packages/aws-cdk-lib/aws-kms/lib/alias.ts b/packages/aws-cdk-lib/aws-kms/lib/alias.ts index cc77cc50ed420..c1957957a9825 100644 --- a/packages/aws-cdk-lib/aws-kms/lib/alias.ts +++ b/packages/aws-cdk-lib/aws-kms/lib/alias.ts @@ -59,6 +59,12 @@ abstract class AliasBase extends Resource implements IAlias { public abstract readonly aliasTargetKey: IKey; + /** + * The ARN of the alias. + * + * @attribute + * @deprecated use `aliasArn` instead + */ public get keyArn(): string { return Stack.of(this).formatArn({ service: 'kms', @@ -67,6 +73,15 @@ abstract class AliasBase extends Resource implements IAlias { }); } + /** + * The ARN of the alias. + * + * @attribute + */ + public get aliasArn(): string { + return this.keyArn; + } + public get keyId(): string { return this.aliasName; } diff --git a/packages/aws-cdk-lib/aws-kms/test/alias.test.ts b/packages/aws-cdk-lib/aws-kms/test/alias.test.ts index e629b46ec1744..f631c97490f29 100644 --- a/packages/aws-cdk-lib/aws-kms/test/alias.test.ts +++ b/packages/aws-cdk-lib/aws-kms/test/alias.test.ts @@ -357,6 +357,16 @@ test('does not add alias if starts with token', () => { }); }); +test('aliasArn and keyArn from alias should match', () => { + const app = new App(); + const stack = new Stack(app, 'Test'); + const key = new Key(stack, 'Key'); + + const alias = new Alias(stack, 'Alias', { targetKey: key, aliasName: 'alias/foo' }); + + expect(alias.aliasArn).toEqual(alias.keyArn); +}); + class AliasOutputsConstruct extends Construct { constructor(scope: Construct, id: string, key: IKey) { super(scope, id);