@@ -3,7 +3,6 @@ import * as rds from '@aws-cdk/aws-rds';
3
3
import * as cdk from '@aws-cdk/core' ;
4
4
import { SecretValue } from '@aws-cdk/core' ;
5
5
import * as ssm from '@aws-cdk/aws-ssm' ;
6
- import { ParameterGroup } from '@aws-cdk/aws-rds' ;
7
6
8
7
export interface DatabaseProps extends cdk . StackProps {
9
8
readonly clusterName : string ;
@@ -17,18 +16,14 @@ export interface DatabaseProps extends cdk.StackProps {
17
16
18
17
export class Database extends cdk . Stack {
19
18
readonly credentials : string
20
- readonly endpoint : string
21
- readonly username : string
22
- readonly port : string
23
- readonly database : string
24
- readonly region : string
25
19
26
20
constructor ( scope : cdk . Construct , id : string , props : DatabaseProps ) {
27
21
super ( scope , id , props ) ;
28
22
23
+ const rdsVersion = rds . MysqlEngineVersion . VER_5_7 ;
29
24
const parameterGroup = new rds . ParameterGroup ( this , "DBParameterGroup" , {
30
25
engine : props . instanceEngine ?? rds . DatabaseInstanceEngine . mysql ( {
31
- version : rds . MysqlEngineVersion . VER_5_7 ,
26
+ version : rdsVersion ,
32
27
} ) ,
33
28
parameters : {
34
29
explicit_defaults_for_timestamp : "OFF"
@@ -37,13 +32,13 @@ export class Database extends cdk.Stack {
37
32
38
33
// TODO: remove when the gitpod helm chart supports using secrets from ssm
39
34
this . credentials = ssm . StringParameter . valueForStringParameter (
40
- this , `/gitpod/cluster/${ props . clusterName } /region/${ props . vpc . stack . region } ` , 1 ) ;
35
+ this , `/gitpod/cluster/${ props . clusterName } /region/${ props . vpc . stack . region } ` ) ;
41
36
42
37
const instance = new rds . DatabaseInstance ( this , 'Gitpod' , {
43
38
vpc : props . vpc ,
44
- vpcPlacement : { subnetType : ec2 . SubnetType . PRIVATE } ,
39
+ vpcSubnets : { subnetType : ec2 . SubnetType . PRIVATE_WITH_NAT } ,
45
40
engine : props . instanceEngine ?? rds . DatabaseInstanceEngine . mysql ( {
46
- version : rds . MysqlEngineVersion . VER_5_7 ,
41
+ version : rdsVersion ,
47
42
} ) ,
48
43
storageEncrypted : true ,
49
44
backupRetention : props . backupRetention ?? cdk . Duration . days ( 7 ) ,
@@ -67,10 +62,17 @@ export class Database extends cdk.Stack {
67
62
// allow from the whole vpc cidr
68
63
instance . connections . allowFrom ( ec2 . Peer . ipv4 ( props . vpc . vpcCidrBlock ) , ec2 . Port . tcp ( 3306 ) ) ;
69
64
70
- this . endpoint = instance . dbInstanceEndpointAddress ;
71
- this . username = props . username ;
72
- this . port = '3306' ;
73
- this . database = 'gitpod' ;
74
- this . region = props . vpc . stack . region ;
65
+ new cdk . CfnOutput ( this , "MysqlEndpoint" , {
66
+ value : instance . dbInstanceEndpointAddress ,
67
+ exportName : "MysqlEndpoint" ,
68
+ } ) ;
69
+ new cdk . CfnOutput ( this , "MysqlUsername" , {
70
+ value : props . username ,
71
+ exportName : "MysqlUsername" ,
72
+ } ) ;
73
+ new cdk . CfnOutput ( this , "MysqlPort" , {
74
+ value : '3306' ,
75
+ exportName : "MysqlPort" ,
76
+ } ) ;
75
77
}
76
78
}
0 commit comments