@studion/infra-code-blocks
Version:
Studion common infra components
47 lines (46 loc) • 1.75 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 common_tags_1 = require("../../shared/common-tags");
class Password extends pulumi.ComponentResource {
name;
value;
secret;
constructor(name, args = {}, opts = {}) {
super('studion:password:Password', name, {}, {
...opts,
aliases: [...(opts.aliases || []), { type: 'studion:Password' }],
});
this.name = name;
if (args.value) {
this.value = pulumi.secret(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: common_tags_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;