Skip to content

Commit

Permalink
Made changes to the RP, updated the test and docs for rds-provider
Browse files Browse the repository at this point in the history
  • Loading branch information
5herlocked committed Jun 20, 2024
1 parent 6d865ce commit 1fab32f
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 11 deletions.
126 changes: 126 additions & 0 deletions docs/resource-providers/rds-providers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Relational Database Service Resource Providers

The relational database resource provider specifically tightly couples the lifetime of the RDS
Resources created with that of the EKS Cluster. It should only be used with a so-called management
cluster that governs the platform.

To prevent accidental deletion of data while rebuilding EKS clusters, the default retention policy
assigned to the RDS instances and clusters is `RetainPolicy.SNAPSHOT` which ensures that while
the cluster and database is being deleted, it is first backed-up and then deleted.

In the management cluster pattern, this resource provider is like resources provisioned with ACK
or Crossplane. Removal of the resource from the management cluster by default will drop such
resources as well.

### CreateRDSInstanceProvider
Creates an RDS Instance and make it available to the blueprint constructs with the provided name.

This method creates an RDS Instance with the database engine of your choice and in the VPC
included in the resource context or creates a VPC for you.

The `rdsProps` transparently exposes the underlying RDS Instance properties and will accept and
pass them upstream to the RDS instance method creating the database.

Example Implementation without providing a custom VPC:
```typescript
const stack = blueprints.EksBlueprint.builder()
.resourceProvider(
GlobalResources.Rds,
new CreateRDSProvider(
{
rdsProps: {
credentials: Credentials.fromGeneratedSecret('admin'),
engine: DatabaseInstanceEngine.mariaDb({
version: MariaDbEngineVersion.VER_10_3
})
},
name: "rds-instance-no-vpc"
}
)
)
.account("123456789")
.region("us-east-1")
.build(app, 'rds-instance-no-vpc');
```

Example Implementation while providing a custom VPC:
```typescript
const stack = blueprints.EksBlueprint.builder()
.resourceProvider(
GlobalResources.Vpc,
new VpcProvider(
undefined,
{
primaryCidr: "10.0.0.0/16"
},
)
)
.resourceProvider(
GlobalResources.Rds,
new CreateRDSProvider({
rdsProps: {
credentials: Credentials.fromGeneratedSecret('admin'),
engine: DatabaseInstanceEngine.postgres({
version: PostgresEngineVersion.VER_15_2
})
},
name: 'rds-instance-w-vpc'
})
)
.account("1234567889")
.region("us-east-1")
.build(app, 'rds-instance-w-vpc');

```

### CreateAuroraClusterProvider
Creates an RDS Aurora Cluster and makes it available to the blueprint constructs with the provided name.

This method creates an RDS Cluster with the database engine of your choice and in the VPC
included in the resource context or creates a VPC for you.

The `rdsProps` transparently exposes the underlying RDS Cluster properties and will accept and
pass them upstream to the RDS cluster method creating the database.
We recommend using either Aurora Serverless or creating specific reader and writer instances.

Example Implementation without providing a custom VPC:
```typescript
const stack = blueprints.EksBlueprint.builder()
.resourceProvider(
GlobalResources.Rds,
new CreateAuroraClusterProvider({
clusterEngine: DatabaseClusterEngine.auroraPostgres(
{ version: AuroraPostgresEngineVersion.VER_14_6 }
),
name: "aurora-cluster-no-vpc"
})
)
.account("123456789")
.region("us-east-1")
.build(app, 'aurora-cluster-no-vpc');
```

Example Implementation while providing a custom VPC:
```typescript
const stack = blueprints.EksBlueprint.builder()
.resourceProvider(
GlobalResources.Vpc,
new VpcProvider(
undefined,
{
primaryCidr: "10.0.0.0/16",
})
)
.resourceProvider(
GlobalResources.Rds,
new CreateAuroraClusterProvider({
clusterEngine: DatabaseClusterEngine.auroraPostgres(
{ version: AuroraPostgresEngineVersion.VER_14_6 }
),
name: "aurora-cluster-w-vpc"
})
)
.account("1234567889")
.region("us-east-1")
.build(app, 'aurora-cluster-w-vpc');
```
8 changes: 0 additions & 8 deletions docs/resource-providers/rds-rp.md

This file was deleted.

4 changes: 2 additions & 2 deletions lib/resource-providers/rds.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {CfnOutput, RemovalPolicy} from "aws-cdk-lib";
import * as ec2 from "aws-cdk-lib/aws-ec2";
import {IVpc} from "aws-cdk-lib/aws-ec2";
import * as ec2 from "aws-cdk-lib/aws-ec2";
import * as rds from "aws-cdk-lib/aws-rds";
import {CfnOutput, RemovalPolicy} from "aws-cdk-lib";
import {GlobalResources, ResourceContext, ResourceProvider} from "../spi";

export interface CreateRDSInstanceProviderProps {
Expand Down
2 changes: 1 addition & 1 deletion test/resource-providers/rds.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ describe("RDSInstanceProvider", () => {
});
});

test("Stack created with arbitrary user props passed to aurora should be honoured", () => {
test("Stack created with arbitrary user props passed to RDS Instance should be honoured", () => {
const app = new App();

const stack = blueprints.EksBlueprint.builder()
Expand Down

0 comments on commit 1fab32f

Please sign in to comment.