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 313c264
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
3 changes: 1 addition & 2 deletions cdk/bin/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ 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");
Expand All @@ -15,7 +14,7 @@ const vpcStack = new VpcStack(app, "VPCStack");
const rdsStack = new RDSStack(app, "RDSStack", {
vpc: vpcStack.vpc,
securityGroup: vpcStack.ingressSecurityGroup,
rdsPwdSecretArn: process.env.RDS_PWD_ARN || ""
stage: "standalone"
});

// Serverless Lambda/API Gateway Graphql API
Expand Down
2 changes: 1 addition & 1 deletion cdk/lib/cdk-pipeline-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class AppStage extends Stage {
this.rdsStack = new RDSStack(this, "RDSStack", {
vpc: vpcStack.vpc,
securityGroup: vpcStack.ingressSecurityGroup,
rdsPwdSecretArn: props?.rdsPasswordSecretArn || ""
stage: id
});

this.apiStack = new GraphqlApiStack(this, "APIStack", {
Expand Down
20 changes: 14 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 @@ -13,8 +12,8 @@ import { SecurityGroup, SubnetType, Vpc } from "@aws-cdk/aws-ec2";

export interface RDSStackProps extends StackProps {
vpc: Vpc;
securityGroup: SecurityGroup;
rdsPwdSecretArn: string;
securityGroup: SecurityGroup,
stage: String
}

export class RDSStack extends Stack {
Expand All @@ -31,9 +30,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
const pwdId = `rds-password-${props.stage}`;
this.rdsPassword = new Secret(this, pwdId, {
secretName: pwdId,
generateSecretString: {
excludeCharacters: `/@" `,
excludePunctuation: true,
includeSpace: false,
excludeNumbers: false,
excludeLowercase: false,
excludeUppercase: false,
passwordLength: 24
}
});

this.postgresRDSInstance = new DatabaseInstance(
Expand Down

0 comments on commit 313c264

Please sign in to comment.