Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(secretsmanager): can't export secret name from Secret #11202

Merged
merged 3 commits into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-secretsmanager/lib/secret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ export class Secret extends SecretBase {
});

this.encryptionKey = props.encryptionKey;
this.secretName = this.physicalName;
this.secretName = parseSecretName(this, this.secretArn);

// @see https://docs.aws.amazon.com/kms/latest/developerguide/services-secrets-manager.html#asm-authz
const principal =
Expand Down
17 changes: 17 additions & 0 deletions packages/@aws-cdk/aws-secretsmanager/test/secret.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,23 @@ test('secretValue', () => {
});
});

describe('secretName', () => {
test.each([undefined, 'mySecret'])('when secretName is %s', (secretName) => {
const secret = new secretsmanager.Secret(stack, 'Secret', {
secretName,
});
new cdk.CfnOutput(stack, 'MySecretName', {
value: secret.secretName,
});

// Creates secret name by parsing ARN.
expect(stack).toHaveOutput({
outputName: 'MySecretName',
outputValue: { 'Fn::Select': [6, { 'Fn::Split': [':', { Ref: 'SecretA720EF05' }] }] },
njlynch marked this conversation as resolved.
Show resolved Hide resolved
});
});
});

test('import by secretArn', () => {
// GIVEN
const secretArn = 'arn:aws:secretsmanager:eu-west-1:111111111111:secret:MySecret-f3gDy9';
Expand Down