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(aws-rds): ability to add an existing security group to RDS cluster #2021

Merged
merged 1 commit into from
Mar 15, 2019
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
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-rds/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ export class DatabaseCluster extends cdk.Construct implements IDatabaseCluster {
subnetIds: subnets.map(s => s.subnetId)
});

const securityGroup = new ec2.SecurityGroup(this, 'SecurityGroup', {
const securityGroup = props.instanceProps.securityGroup !== undefined ?
props.instanceProps.securityGroup : new ec2.SecurityGroup(this, 'SecurityGroup', {
description: 'RDS security group',
vpc: props.instanceProps.vpc
});
Expand Down
5 changes: 5 additions & 0 deletions packages/@aws-cdk/aws-rds/lib/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ export interface InstanceProps {
* Where to place the instances within the VPC
*/
vpcPlacement?: ec2.VpcPlacementStrategy;

/**
* Security group. If not specified a new one will be created.
*/
securityGroup?: ec2.ISecurityGroup;
}

/**
Expand Down
37 changes: 37 additions & 0 deletions packages/@aws-cdk/aws-rds/test/test.cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,43 @@ export = {
test.done();
},

'can create a cluster with imported vpc and security group'(test: Test) {
// GIVEN
const stack = testStack();
const vpc = ec2.VpcNetwork.importFromContext(stack, 'VPC', {
vpcId: "VPC12345"
});
const sg = ec2.SecurityGroup.import(stack, 'SG', {
securityGroupId: "SecurityGroupId12345"
});

// WHEN
new DatabaseCluster(stack, 'Database', {
engine: DatabaseClusterEngine.Aurora,
instances: 1,
masterUser: {
username: 'admin',
password: 'tooshort',
},
instanceProps: {
instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.Burstable2, ec2.InstanceSize.Small),
vpc,
securityGroup: sg
}
});

// THEN
expect(stack).to(haveResource('AWS::RDS::DBCluster', {
Engine: "aurora",
DBSubnetGroupName: { Ref: "DatabaseSubnets56F17B9A" },
MasterUsername: "admin",
MasterUserPassword: "tooshort",
VpcSecurityGroupIds: [ "SecurityGroupId12345" ]
}));

test.done();
},

'cluster with parameter group'(test: Test) {
// GIVEN
const stack = testStack();
Expand Down