@@ -10,8 +10,6 @@ import { Route } from '../../../.gen/providers/aws/route';
1010import { SecurityGroup } from '../../../.gen/providers/aws/security-group' ;
1111import { DbSubnetGroup } from '../../../.gen/providers/aws/db-subnet-group' ;
1212import { DbInstance } from '../../../.gen/providers/aws/db-instance' ;
13- import { SecretsmanagerSecret } from '../../../.gen/providers/aws/secretsmanager-secret' ;
14- import { SecretsmanagerSecretVersion } from '../../../.gen/providers/aws/secretsmanager-secret-version' ;
1513import { EcrRepository } from '../../../.gen/providers/aws/ecr-repository' ;
1614import { ApprunnerVpcConnector } from '../../../.gen/providers/aws/apprunner-vpc-connector' ;
1715import { ApprunnerService } from '../../../.gen/providers/aws/apprunner-service' ;
@@ -20,8 +18,6 @@ import { IamRolePolicy } from '../../../.gen/providers/aws/iam-role-policy';
2018import { IamRolePolicyAttachment } from '../../../.gen/providers/aws/iam-role-policy-attachment' ;
2119import { DataAwsAvailabilityZones } from '../../../.gen/providers/aws/data-aws-availability-zones' ;
2220
23- import { getDatabaseSecretKey } from '@flexion/forms-infra-core' ;
24-
2521interface SandboxStackConfig {
2622 environment : string ;
2723}
@@ -151,28 +147,8 @@ export class SandboxStack extends Construct {
151147 } ,
152148 } ) ;
153149
154- // Generate random password for database
150+ // Database username ( password will be managed by RDS in Secrets Manager)
155151 const dbUsername = 'postgres' ;
156- const dbPassword = Fn . base64encode (
157- Fn . uuid ( ) // Use UUID for a secure random password
158- ) ;
159-
160- // Database secret (only username and password - host/port/db passed as env vars)
161- const dbSecret = new SecretsmanagerSecret ( this , `${ id } -db-secret` , {
162- name : getDatabaseSecretKey ( environment ) ,
163- description : `Database credentials for ${ environment } ` ,
164- tags : {
165- Environment : environment ,
166- } ,
167- } ) ;
168-
169- new SecretsmanagerSecretVersion ( this , `${ id } -db-secret-version` , {
170- secretId : dbSecret . id ,
171- secretString : Fn . jsonencode ( {
172- username : dbUsername ,
173- password : dbPassword ,
174- } ) ,
175- } ) ;
176152
177153 // RDS Subnet Group
178154 const dbSubnetGroup = new DbSubnetGroup ( this , `${ id } -db-subnet-group` , {
@@ -184,7 +160,7 @@ export class SandboxStack extends Construct {
184160 } ,
185161 } ) ;
186162
187- // RDS Instance
163+ // RDS Instance with AWS-managed password in Secrets Manager
188164 const rdsInstance = new DbInstance ( this , `${ id } -db` , {
189165 identifier : `${ id } -db` ,
190166 engine : 'postgres' ,
@@ -194,7 +170,7 @@ export class SandboxStack extends Construct {
194170 maxAllocatedStorage : 100 ,
195171 dbName : 'postgres' ,
196172 username : dbUsername ,
197- password : dbPassword ,
173+ manageMasterUserPassword : true ,
198174 dbSubnetGroupName : dbSubnetGroup . name ,
199175 vpcSecurityGroupIds : [ rdsSecurityGroup . id ] ,
200176 publiclyAccessible : false ,
@@ -340,7 +316,11 @@ export class SandboxStack extends Construct {
340316 DB_NAME : 'postgres' ,
341317 } ,
342318 runtimeEnvironmentSecrets : {
343- DB_SECRET : dbSecret . arn ,
319+ DB_SECRET : Fn . lookup (
320+ Fn . element ( rdsInstance . masterUserSecret , 0 ) ,
321+ 'secret_arn' ,
322+ ''
323+ ) ,
344324 } ,
345325 } ,
346326 } ,
0 commit comments