@studion/infra-code-blocks
Version:
Studion common infra components
44 lines (43 loc) • 1.71 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Password = void 0;
const aws = require("@pulumi/aws");
const pulumi = require("@pulumi/pulumi");
const random = require("@pulumi/random");
const constants_1 = require("../constants");
class Password extends pulumi.ComponentResource {
constructor(name, args, opts = {}) {
const optsWithDefauls = pulumi.mergeOptions(opts, {
additionalSecretOutputs: ['value'],
});
super('studion:Password', name, {}, optsWithDefauls);
this.name = name;
if (args.value) {
this.value = pulumi.output(args.value);
}
else {
const password = new random.RandomPassword(`${this.name}-random-password`, {
length: 16,
overrideSpecial: '_$',
special: true,
}, { parent: this });
this.value = password.result;
}
this.secret = this.createPasswordSecret(this.value);
this.registerOutputs();
}
createPasswordSecret(password) {
const project = pulumi.getProject();
const stack = pulumi.getStack();
const passwordSecret = new aws.secretsmanager.Secret(`${this.name}-password-secret`, {
namePrefix: `${stack}/${project}/${this.name}-`,
tags: constants_1.commonTags,
}, { parent: this });
const passwordSecretValue = new aws.secretsmanager.SecretVersion(`${this.name}-password-secret-value`, {
secretId: passwordSecret.id,
secretString: password,
}, { parent: this, dependsOn: [passwordSecret] });
return passwordSecret;
}
}
exports.Password = Password;