Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Mar 3, 2022
2 parents 3f60aa6 + 3382e99 commit f9907cf
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 43 deletions.
37 changes: 19 additions & 18 deletions packages/@aws-cdk/aws-rds/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,21 @@ interface DatabaseClusterBaseProps {
* @default false
*/
readonly iamAuthentication?: boolean;

/**
* Whether to enable storage encryption.
*
* @default - true if storageEncryptionKey is provided, false otherwise
*/
readonly storageEncrypted?: boolean

/**
* The KMS key for storage encryption.
* If specified, {@link storageEncrypted} will be set to `true`.
*
* @default - if storageEncrypted is true then the default master key, no key otherwise
*/
readonly storageEncryptionKey?: kms.IKey;
}

/**
Expand Down Expand Up @@ -402,6 +417,9 @@ abstract class DatabaseClusterNew extends DatabaseClusterBase {
preferredMaintenanceWindow: props.preferredMaintenanceWindow,
databaseName: props.defaultDatabaseName,
enableCloudwatchLogsExports: props.cloudwatchLogsExports,
// Encryption
kmsKeyId: props.storageEncryptionKey?.keyArn,
storageEncrypted: props.storageEncryptionKey ? true : props.storageEncrypted,
};
}
}
Expand Down Expand Up @@ -479,21 +497,6 @@ export interface DatabaseClusterProps extends DatabaseClusterBaseProps {
*/
readonly credentials?: Credentials;

/**
* Whether to enable storage encryption.
*
* @default - true if storageEncryptionKey is provided, false otherwise
*/
readonly storageEncrypted?: boolean

/**
* The KMS key for storage encryption.
* If specified, {@link storageEncrypted} will be set to `true`.
*
* @default - if storageEncrypted is true then the default master key, no key otherwise
*/
readonly storageEncryptionKey?: kms.IKey;

/**
* Whether to copy tags to the snapshot when a snapshot is created.
*
Expand Down Expand Up @@ -550,9 +553,7 @@ export class DatabaseCluster extends DatabaseClusterNew {
// Admin
masterUsername: credentials.username,
masterUserPassword: credentials.password?.toString(),
// Encryption
kmsKeyId: props.storageEncryptionKey?.keyArn,
storageEncrypted: props.storageEncryptionKey ? true : props.storageEncrypted,
// Tags
copyTagsToSnapshot: props.copyTagsToSnapshot ?? true,
});

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

test('create a cluster from a snapshot with encrypted storage', () => {
const stack = testStack();
const vpc = new ec2.Vpc(stack, 'VPC');

// WHEN
new DatabaseClusterFromSnapshot(stack, 'Database', {
engine: DatabaseClusterEngine.aurora({ version: AuroraEngineVersion.VER_1_22_2 }),
instanceProps: {
vpc,
},
snapshotIdentifier: 'mySnapshot',
storageEncryptionKey: kms.Key.fromKeyArn(stack, 'Key', 'arn:aws:kms:us-east-1:456:key/my-key'),
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::RDS::DBCluster', {
KmsKeyId: 'arn:aws:kms:us-east-1:456:key/my-key',
StorageEncrypted: true,
});
});

test('reuse an existing subnet group', () => {
// GIVEN
const stack = testStack();
Expand Down
Loading

0 comments on commit f9907cf

Please sign in to comment.