Skip to content

Commit 2a7300d

Browse files
committed
Store db password as a secret
1 parent 71e17b1 commit 2a7300d

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

src/components/database.ts

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export type DatabaseArgs = {
1616
*/
1717
vpc: awsx.ec2.Vpc;
1818
/**
19-
* Password for the master DB user. If not specified, it will be autogenerated
20-
* and stored as a secret in AWS Secret Manager.
19+
* Password for the master DB user. If not specified, it will be autogenerated.
20+
* The value will be stored as a secret in AWS Secret Manager.
2121
*/
2222
password?: pulumi.Input<string>;
2323
/**
@@ -61,7 +61,7 @@ export class Database extends pulumi.ComponentResource {
6161
kms: aws.kms.Key;
6262
dbSubnetGroup: aws.rds.SubnetGroup;
6363
dbSecurityGroup: aws.ec2.SecurityGroup;
64-
passwordSecret?: aws.secretsmanager.Secret;
64+
passwordSecret: aws.secretsmanager.Secret;
6565

6666
constructor(
6767
name: string,
@@ -118,24 +118,22 @@ export class Database extends pulumi.ComponentResource {
118118
.getRandomPasswordOutput()
119119
.apply(res => res.randomPassword);
120120

121-
if (!argsWithDefaults.password) {
122-
this.passwordSecret = new aws.secretsmanager.Secret(
123-
`${name}-password-secret`,
124-
{
125-
name: `${stack}/${project}/DatabasePassword`,
126-
},
127-
{ parent: this },
128-
);
121+
this.passwordSecret = new aws.secretsmanager.Secret(
122+
`${name}-password-secret`,
123+
{
124+
name: `${stack}/${project}/DatabasePassword`,
125+
},
126+
{ parent: this },
127+
);
129128

130-
const passwordSecretValue = new aws.secretsmanager.SecretVersion(
131-
`${name}-password-secret-value`,
132-
{
133-
secretId: this.passwordSecret.id,
134-
secretString: password,
135-
},
136-
{ parent: this, dependsOn: [this.passwordSecret] },
137-
);
138-
}
129+
const passwordSecretValue = new aws.secretsmanager.SecretVersion(
130+
`${name}-password-secret-value`,
131+
{
132+
secretId: this.passwordSecret.id,
133+
secretString: password,
134+
},
135+
{ parent: this, dependsOn: [this.passwordSecret] },
136+
);
139137

140138
this.instance = new aws.rds.Instance(
141139
`${name}-rds`,

0 commit comments

Comments
 (0)