@@ -797,14 +797,17 @@ describe('instance', () => {
797
797
} ) ;
798
798
} ) ;
799
799
800
- test ( 'addRotationSingleUser() with options ' , ( ) => {
800
+ test ( 'addRotationSingleUser() with custom automaticallyAfter, excludeCharacters and vpcSubnets ' , ( ) => {
801
801
// GIVEN
802
- const vpcWithIsolated = new ec2 . Vpc ( stack , 'Vpc' , {
803
- subnetConfiguration : [
804
- { name : 'public' , subnetType : ec2 . SubnetType . PUBLIC } ,
805
- { name : 'private' , subnetType : ec2 . SubnetType . PRIVATE_WITH_NAT } ,
806
- { name : 'isolated' , subnetType : ec2 . SubnetType . PRIVATE_ISOLATED } ,
807
- ] ,
802
+ const vpcWithIsolated = ec2 . Vpc . fromVpcAttributes ( stack , 'Vpc' , {
803
+ vpcId : 'vpc-id' ,
804
+ availabilityZones : [ 'az1' ] ,
805
+ publicSubnetIds : [ 'public-subnet-id-1' , 'public-subnet-id-2' ] ,
806
+ publicSubnetNames : [ 'public-subnet-name-1' , 'public-subnet-name-2' ] ,
807
+ privateSubnetIds : [ 'private-subnet-id-1' , 'private-subnet-id-2' ] ,
808
+ privateSubnetNames : [ 'private-subnet-name-1' , 'private-subnet-name-2' ] ,
809
+ isolatedSubnetIds : [ 'isolated-subnet-id-1' , 'isolated-subnet-id-2' ] ,
810
+ isolatedSubnetNames : [ 'isolated-subnet-name-1' , 'isolated-subnet-name-2' ] ,
808
811
} ) ;
809
812
810
813
// WHEN
@@ -839,26 +842,69 @@ describe('instance', () => {
839
842
{ Ref : 'AWS::URLSuffix' } ,
840
843
] ] ,
841
844
} ,
842
- functionName : 'DatabaseRotationSingleUser458A45BE' ,
843
- vpcSubnetIds : {
845
+ vpcSubnetIds : 'private-subnet-id-1,private-subnet-id-2' ,
846
+ excludeCharacters : '°_@' ,
847
+ } ,
848
+ } ) ;
849
+ } ) ;
850
+
851
+ test ( 'addRotationMultiUser() with custom automaticallyAfter, excludeCharacters and vpcSubnets' , ( ) => {
852
+ // GIVEN
853
+ const vpcWithIsolated = ec2 . Vpc . fromVpcAttributes ( stack , 'Vpc' , {
854
+ vpcId : 'vpc-id' ,
855
+ availabilityZones : [ 'az1' ] ,
856
+ publicSubnetIds : [ 'public-subnet-id-1' , 'public-subnet-id-2' ] ,
857
+ publicSubnetNames : [ 'public-subnet-name-1' , 'public-subnet-name-2' ] ,
858
+ privateSubnetIds : [ 'private-subnet-id-1' , 'private-subnet-id-2' ] ,
859
+ privateSubnetNames : [ 'private-subnet-name-1' , 'private-subnet-name-2' ] ,
860
+ isolatedSubnetIds : [ 'isolated-subnet-id-1' , 'isolated-subnet-id-2' ] ,
861
+ isolatedSubnetNames : [ 'isolated-subnet-name-1' , 'isolated-subnet-name-2' ] ,
862
+ } ) ;
863
+ const userSecret = new rds . DatabaseSecret ( stack , 'UserSecret' , { username : 'user' } ) ;
864
+
865
+ // WHEN
866
+ // DB in isolated subnet (no internet connectivity)
867
+ const instance = new rds . DatabaseInstance ( stack , 'Database' , {
868
+ engine : rds . DatabaseInstanceEngine . postgres ( { version : rds . PostgresEngineVersion . VER_10 } ) ,
869
+ vpc : vpcWithIsolated ,
870
+ vpcSubnets : { subnetType : ec2 . SubnetType . PRIVATE_ISOLATED } ,
871
+ } ) ;
872
+
873
+ // Rotation in private subnet (internet via NAT)
874
+ instance . addRotationMultiUser ( 'user' , {
875
+ secret : userSecret . attach ( instance ) ,
876
+ automaticallyAfter : cdk . Duration . days ( 15 ) ,
877
+ excludeCharacters : '°_@' ,
878
+ vpcSubnets : { subnetType : ec2 . SubnetType . PRIVATE_WITH_NAT } ,
879
+ } ) ;
880
+
881
+ // THEN
882
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::SecretsManager::RotationSchedule' , {
883
+ RotationRules : {
884
+ AutomaticallyAfterDays : 15 ,
885
+ } ,
886
+ } ) ;
887
+
888
+ vpcWithIsolated . selectSubnets ( {
889
+ subnetType : ec2 . SubnetType . PRIVATE_WITH_NAT ,
890
+ } ) . subnetIds ;
891
+
892
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::Serverless::Application' , {
893
+ Parameters : {
894
+ endpoint : {
844
895
'Fn::Join' : [ '' , [
845
- { Ref : 'VpcprivateSubnet1SubnetCEAD3716' } ,
846
- ',' ,
847
- { Ref : 'VpcprivateSubnet2Subnet2DE7549C' } ,
896
+ 'https://secretsmanager.' ,
897
+ { Ref : 'AWS::Region' } ,
898
+ '.' ,
899
+ { Ref : 'AWS::URLSuffix' } ,
848
900
] ] ,
849
901
} ,
850
- vpcSecurityGroupIds : {
851
- 'Fn::GetAtt' : [
852
- 'DatabaseRotationSingleUserSecurityGroupAC6E0E73' ,
853
- 'GroupId' ,
854
- ] ,
855
- } ,
902
+ vpcSubnetIds : 'private-subnet-id-1,private-subnet-id-2' ,
856
903
excludeCharacters : '°_@' ,
857
904
} ,
858
905
} ) ;
859
906
} ) ;
860
907
861
-
862
908
test ( 'addRotationSingleUser() with VPC interface endpoint' , ( ) => {
863
909
// GIVEN
864
910
const vpcIsolatedOnly = new ec2 . Vpc ( stack , 'Vpc' , { natGateways : 0 } ) ;
0 commit comments