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

feat(docdb): add option to set the name of the generated Secret #17574

Merged
merged 7 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-docdb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const cluster = new DatabaseCluster(this, 'Database', {
masterUser: {
username: 'myuser' // NOTE: 'admin' is reserved by DocumentDB
excludeCharacters: '\"@/:', // optional, defaults to the set "\"@/"
secretName: '/myapp/mydocdb/masteruser', // optional, if you prefer to specify the secret name
},
instanceType: ec2.InstanceType.of(ec2.InstanceClass.R5, ec2.InstanceSize.LARGE),
vpcSubnets: {
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-docdb/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ export class DatabaseCluster extends DatabaseClusterBase {
username: props.masterUser.username,
encryptionKey: props.masterUser.kmsKey,
excludeCharacters: props.masterUser.excludeCharacters,
secretName: props.masterUser.secretName,
});
}

Expand Down
7 changes: 7 additions & 0 deletions packages/@aws-cdk/aws-docdb/lib/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ export interface Login {
* @default "\"@/"
*/
readonly excludeCharacters?: string;

/**
* The physical name of the secret, that will be generated.
*
* @default Secretsmanager will generate a physical name for the secret
*/
readonly secretName?: string;
}

/**
Expand Down
21 changes: 21 additions & 0 deletions packages/@aws-cdk/aws-docdb/test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,27 @@ describe('DatabaseCluster', () => {
}));
});

test('creates a secret with secretName set', () => {
// GIVEN
const stack = testStack();
const vpc = new ec2.Vpc(stack, 'VPC');

// WHEN
new DatabaseCluster(stack, 'Database', {
masterUser: {
username: 'admin',
secretName: '/myapp/mydocdb/masteruser',
},
instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.SMALL),
vpc,
});

// THEN
expectCDK(stack).to(haveResourceLike('AWS::SecretsManager::Secret', {
Name: '/myapp/mydocdb/masteruser',
}));
});

test('create an encrypted cluster with custom KMS key', () => {
// GIVEN
const stack = testStack();
Expand Down