Skip to content

Commit

Permalink
Merge pull request #186 from adamstortz/add-config-for-database-remov…
Browse files Browse the repository at this point in the history
…al-policy

feat: adds database removal policy to props
  • Loading branch information
wchaws authored Mar 6, 2023
2 parents fa16a03 + 9af577f commit 71d3bf4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
9 changes: 7 additions & 2 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ new Database(scope: Construct, id: string, props: DatabaseProps)
* **instanceType** (<code>[aws_ec2.InstanceType](#aws-cdk-lib-aws-ec2-instancetype)</code>) The database instance type. __*Default*__: r5.large
* **maxCapacity** (<code>number</code>) The maximum number of Aurora Serverless V2 capacity units. __*Default*__: 10
* **minCapacity** (<code>number</code>) The minimum number of Aurora Serverless V2 capacity units. __*Default*__: 0.5
* **removalPolicy** (<code>[RemovalPolicy](#aws-cdk-lib-removalpolicy)</code>) Controls what happens to the database if it stops being managed by CloudFormation. __*Default*__: RemovalPolicy.RETAIN
* **singleDbInstance** (<code>boolean</code>) Whether to use single RDS instance rather than RDS cluster. __*Default*__: false


Expand Down Expand Up @@ -144,10 +145,11 @@ new KeyCloak(scope: Construct, id: string, props: KeyCloakProps)
* **databaseInstanceType** (<code>[aws_ec2.InstanceType](#aws-cdk-lib-aws-ec2-instancetype)</code>) Database instance type. __*Default*__: r5.large
* **databaseMaxCapacity** (<code>number</code>) The maximum number of Aurora Serverless V2 capacity units. __*Default*__: 10
* **databaseMinCapacity** (<code>number</code>) The minimum number of Aurora Serverless V2 capacity units. __*Default*__: 0.5
* **databaseRemovalPolicy** (<code>[RemovalPolicy](#aws-cdk-lib-removalpolicy)</code>) Controls what happens to the database if it stops being managed by CloudFormation. __*Default*__: RemovalPolicy.RETAIN
* **databaseSubnets** (<code>[aws_ec2.SubnetSelection](#aws-cdk-lib-aws-ec2-subnetselection)</code>) VPC subnets for database. __*Default*__: VPC isolated subnets
* **env** (<code>Map<string, string></code>) The environment variables to pass to the keycloak container. __*Optional*__
* **instanceEngine** (<code>[aws_rds.IInstanceEngine](#aws-cdk-lib-aws-rds-iinstanceengine)</code>) The database instance engine. __*Default*__: MySQL 8.0.21
* **internetFacing** (<code>boolean</code>) Whether to put the put the load balancer in the public or private subnets. __*Default*__: true
* **internetFacing** (<code>boolean</code>) Whether to put the load balancer in the public or private subnets. __*Default*__: true
* **nodeCount** (<code>number</code>) Number of keycloak node in the cluster. __*Default*__: 2
* **privateSubnets** (<code>[aws_ec2.SubnetSelection](#aws-cdk-lib-aws-ec2-subnetselection)</code>) VPC private subnets for keycloak service. __*Default*__: VPC private subnets
* **publicSubnets** (<code>[aws_ec2.SubnetSelection](#aws-cdk-lib-aws-ec2-subnetselection)</code>) VPC public subnets for ALB. __*Default*__: VPC public subnets
Expand Down Expand Up @@ -189,6 +191,7 @@ addDatabase(props: DatabaseProps): Database
* **instanceType** (<code>[aws_ec2.InstanceType](#aws-cdk-lib-aws-ec2-instancetype)</code>) The database instance type. __*Default*__: r5.large
* **maxCapacity** (<code>number</code>) The maximum number of Aurora Serverless V2 capacity units. __*Default*__: 10
* **minCapacity** (<code>number</code>) The minimum number of Aurora Serverless V2 capacity units. __*Default*__: 0.5
* **removalPolicy** (<code>[RemovalPolicy](#aws-cdk-lib-removalpolicy)</code>) Controls what happens to the database if it stops being managed by CloudFormation. __*Default*__: RemovalPolicy.RETAIN
* **singleDbInstance** (<code>boolean</code>) Whether to use single RDS instance rather than RDS cluster. __*Default*__: false

__Returns__:
Expand Down Expand Up @@ -335,6 +338,7 @@ Name | Type | Description
**instanceType**? | <code>[aws_ec2.InstanceType](#aws-cdk-lib-aws-ec2-instancetype)</code> | The database instance type.<br/>__*Default*__: r5.large
**maxCapacity**? | <code>number</code> | The maximum number of Aurora Serverless V2 capacity units.<br/>__*Default*__: 10
**minCapacity**? | <code>number</code> | The minimum number of Aurora Serverless V2 capacity units.<br/>__*Default*__: 0.5
**removalPolicy**? | <code>[RemovalPolicy](#aws-cdk-lib-removalpolicy)</code> | Controls what happens to the database if it stops being managed by CloudFormation.<br/>__*Default*__: RemovalPolicy.RETAIN
**singleDbInstance**? | <code>boolean</code> | Whether to use single RDS instance rather than RDS cluster.<br/>__*Default*__: false


Expand All @@ -359,10 +363,11 @@ Name | Type | Description
**databaseInstanceType**? | <code>[aws_ec2.InstanceType](#aws-cdk-lib-aws-ec2-instancetype)</code> | Database instance type.<br/>__*Default*__: r5.large
**databaseMaxCapacity**? | <code>number</code> | The maximum number of Aurora Serverless V2 capacity units.<br/>__*Default*__: 10
**databaseMinCapacity**? | <code>number</code> | The minimum number of Aurora Serverless V2 capacity units.<br/>__*Default*__: 0.5
**databaseRemovalPolicy**? | <code>[RemovalPolicy](#aws-cdk-lib-removalpolicy)</code> | Controls what happens to the database if it stops being managed by CloudFormation.<br/>__*Default*__: RemovalPolicy.RETAIN
**databaseSubnets**? | <code>[aws_ec2.SubnetSelection](#aws-cdk-lib-aws-ec2-subnetselection)</code> | VPC subnets for database.<br/>__*Default*__: VPC isolated subnets
**env**? | <code>Map<string, string></code> | The environment variables to pass to the keycloak container.<br/>__*Optional*__
**instanceEngine**? | <code>[aws_rds.IInstanceEngine](#aws-cdk-lib-aws-rds-iinstanceengine)</code> | The database instance engine.<br/>__*Default*__: MySQL 8.0.21
**internetFacing**? | <code>boolean</code> | Whether to put the put the load balancer in the public or private subnets.<br/>__*Default*__: true
**internetFacing**? | <code>boolean</code> | Whether to put the load balancer in the public or private subnets.<br/>__*Default*__: true
**nodeCount**? | <code>number</code> | Number of keycloak node in the cluster.<br/>__*Default*__: 2
**privateSubnets**? | <code>[aws_ec2.SubnetSelection](#aws-cdk-lib-aws-ec2-subnetselection)</code> | VPC private subnets for keycloak service.<br/>__*Default*__: VPC private subnets
**publicSubnets**? | <code>[aws_ec2.SubnetSelection](#aws-cdk-lib-aws-ec2-subnetselection)</code> | VPC public subnets for ALB.<br/>__*Default*__: VPC public subnets
Expand Down
25 changes: 20 additions & 5 deletions src/keycloak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export interface KeyCloakProps {
readonly autoScaleTask?: AutoScaleTask;

/**
* Whether to put the put the load balancer in the public or private subnets
* Whether to put the load balancer in the public or private subnets
*
* @default true
*/
Expand All @@ -226,6 +226,13 @@ export interface KeyCloakProps {
* @default 10
*/
readonly databaseMaxCapacity?: number;

/**
* Controls what happens to the database if it stops being managed by CloudFormation
*
* @default RemovalPolicy.RETAIN
*/
readonly databaseRemovalPolicy?: cdk.RemovalPolicy;
}

export class KeyCloak extends Construct {
Expand Down Expand Up @@ -257,6 +264,7 @@ export class KeyCloak extends Construct {
backupRetention: props.backupRetention,
maxCapacity: props.databaseMaxCapacity,
minCapacity: props.databaseMinCapacity,
removalPolicy: props.databaseRemovalPolicy,
});
const keycloakContainerService = this.addKeyCloakContainerService({
database: this.db,
Expand Down Expand Up @@ -360,6 +368,13 @@ export interface DatabaseProps {
* @default 10
*/
readonly maxCapacity?: number;

/**
* Controls what happens to the database if it stops being managed by CloudFormation
*
* @default RemovalPolicy.RETAIN
*/
readonly removalPolicy?: cdk.RemovalPolicy;
}

/**
Expand Down Expand Up @@ -434,7 +449,7 @@ export class Database extends Construct {
instanceType: props.instanceType ?? new ec2.InstanceType('r5.large'),
parameterGroup: rds.ParameterGroup.fromParameterGroupName(this, 'ParameterGroup', 'default.mysql8.0'),
deletionProtection: true,
removalPolicy: cdk.RemovalPolicy.RETAIN,
removalPolicy: props.removalPolicy ?? cdk.RemovalPolicy.RETAIN,
});
return {
connections: dbInstance.connections,
Expand Down Expand Up @@ -462,7 +477,7 @@ export class Database extends Construct {
retention: props.backupRetention ?? cdk.Duration.days(7),
},
storageEncrypted: true,
removalPolicy: cdk.RemovalPolicy.RETAIN,
removalPolicy: props.removalPolicy ?? cdk.RemovalPolicy.RETAIN,
});
return {
connections: dbCluster.connections,
Expand All @@ -480,7 +495,7 @@ export class Database extends Construct {
credentials: rds.Credentials.fromGeneratedSecret('admin'),
backupRetention: props.backupRetention ?? cdk.Duration.days(7),
deletionProtection: true,
removalPolicy: cdk.RemovalPolicy.RETAIN,
removalPolicy: props.removalPolicy ?? cdk.RemovalPolicy.RETAIN,
parameterGroup: rds.ParameterGroup.fromParameterGroupName(this, 'ParameterGroup', 'default.aurora-mysql5.7'),
});
return {
Expand Down Expand Up @@ -511,7 +526,7 @@ export class Database extends Construct {
retention: props.backupRetention ?? cdk.Duration.days(7),
},
storageEncrypted: true,
removalPolicy: cdk.RemovalPolicy.RETAIN,
removalPolicy: props.removalPolicy ?? cdk.RemovalPolicy.RETAIN,
});
// Set Serverless V2 Scaling Configuration
// TODO: Use cleaner way to set scaling configuration.
Expand Down

0 comments on commit 71d3bf4

Please sign in to comment.