Skip to content

Commit

Permalink
generating rds secret
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Tinn committed Oct 6, 2021
1 parent 3b73324 commit 5844aca
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
4 changes: 1 addition & 3 deletions cdk/bin/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ import { VpcStack } from "../lib/vpc-stack";
import { RDSStack } from "../lib/rds-stack";

const app = new cdk.App();
const rdsPasswordArnSsmParamName = "rds-password-secret-arn"

// Basic networking
const vpcStack = new VpcStack(app, "VPCStack");

// RDS Postgres
const rdsStack = new RDSStack(app, "RDSStack", {
vpc: vpcStack.vpc,
securityGroup: vpcStack.ingressSecurityGroup,
rdsPwdSecretArn: process.env.RDS_PWD_ARN || ""
securityGroup: vpcStack.ingressSecurityGroup
});

// Serverless Lambda/API Gateway Graphql API
Expand Down
3 changes: 1 addition & 2 deletions cdk/lib/cdk-pipeline-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ class AppStage extends Stage {

this.rdsStack = new RDSStack(this, "RDSStack", {
vpc: vpcStack.vpc,
securityGroup: vpcStack.ingressSecurityGroup,
rdsPwdSecretArn: props?.rdsPasswordSecretArn || ""
securityGroup: vpcStack.ingressSecurityGroup
});

this.apiStack = new GraphqlApiStack(this, "APIStack", {
Expand Down
18 changes: 12 additions & 6 deletions cdk/lib/rds-stack.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require("dotenv").config();
import { Construct, Stack, StackProps, CfnOutput } from "@aws-cdk/core";
import { StringParameter } from '@aws-cdk/aws-ssm';

import {
DatabaseInstance,
Expand All @@ -14,7 +13,6 @@ import { SecurityGroup, SubnetType, Vpc } from "@aws-cdk/aws-ec2";
export interface RDSStackProps extends StackProps {
vpc: Vpc;
securityGroup: SecurityGroup;
rdsPwdSecretArn: string;
}

export class RDSStack extends Stack {
Expand All @@ -30,10 +28,18 @@ export class RDSStack extends Stack {

constructor(scope: Construct, id: string, props: RDSStackProps) {
super(scope, id, props);


this.rdsPassword = Secret.fromSecretAttributes(this, "rdsPassword", {
secretArn: props.rdsPwdSecretArn

this.rdsPassword = new Secret(this, "rds-password", {
secretName: "rds-password",
generateSecretString: {
excludeCharacters: `/@" `,
excludePunctuation: true,
includeSpace: false,
excludeNumbers: false,
excludeLowercase: false,
excludeUppercase: false,
passwordLength: 24
}
});

this.postgresRDSInstance = new DatabaseInstance(
Expand Down

0 comments on commit 5844aca

Please sign in to comment.