File tree 3 files changed +44
-1
lines changed
packages/@aws-cdk/aws-rds
3 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -151,7 +151,8 @@ export class DatabaseCluster extends cdk.Construct implements IDatabaseCluster {
151
151
subnetIds : subnets . map ( s => s . subnetId )
152
152
} ) ;
153
153
154
- const securityGroup = new ec2 . SecurityGroup ( this , 'SecurityGroup' , {
154
+ const securityGroup = props . instanceProps . securityGroup !== undefined ?
155
+ props . instanceProps . securityGroup : new ec2 . SecurityGroup ( this , 'SecurityGroup' , {
155
156
description : 'RDS security group' ,
156
157
vpc : props . instanceProps . vpc
157
158
} ) ;
Original file line number Diff line number Diff line change @@ -30,6 +30,11 @@ export interface InstanceProps {
30
30
* Where to place the instances within the VPC
31
31
*/
32
32
vpcPlacement ?: ec2 . VpcPlacementStrategy ;
33
+
34
+ /**
35
+ * Security group. If not specified a new one will be created.
36
+ */
37
+ securityGroup ?: ec2 . ISecurityGroup ;
33
38
}
34
39
35
40
/**
Original file line number Diff line number Diff line change @@ -89,6 +89,43 @@ export = {
89
89
test . done ( ) ;
90
90
} ,
91
91
92
+ 'can create a cluster with imported vpc and security group' ( test : Test ) {
93
+ // GIVEN
94
+ const stack = testStack ( ) ;
95
+ const vpc = ec2 . VpcNetwork . importFromContext ( stack , 'VPC' , {
96
+ vpcId : "VPC12345"
97
+ } ) ;
98
+ const sg = ec2 . SecurityGroup . import ( stack , 'SG' , {
99
+ securityGroupId : "SecurityGroupId12345"
100
+ } ) ;
101
+
102
+ // WHEN
103
+ new DatabaseCluster ( stack , 'Database' , {
104
+ engine : DatabaseClusterEngine . Aurora ,
105
+ instances : 1 ,
106
+ masterUser : {
107
+ username : 'admin' ,
108
+ password : 'tooshort' ,
109
+ } ,
110
+ instanceProps : {
111
+ instanceType : new ec2 . InstanceTypePair ( ec2 . InstanceClass . Burstable2 , ec2 . InstanceSize . Small ) ,
112
+ vpc,
113
+ securityGroup : sg
114
+ }
115
+ } ) ;
116
+
117
+ // THEN
118
+ expect ( stack ) . to ( haveResource ( 'AWS::RDS::DBCluster' , {
119
+ Engine : "aurora" ,
120
+ DBSubnetGroupName : { Ref : "DatabaseSubnets56F17B9A" } ,
121
+ MasterUsername : "admin" ,
122
+ MasterUserPassword : "tooshort" ,
123
+ VpcSecurityGroupIds : [ "SecurityGroupId12345" ]
124
+ } ) ) ;
125
+
126
+ test . done ( ) ;
127
+ } ,
128
+
92
129
'cluster with parameter group' ( test : Test ) {
93
130
// GIVEN
94
131
const stack = testStack ( ) ;
You can’t perform that action at this time.
0 commit comments