@studion/infra-code-blocks
Version:
Studion common infra components
64 lines (63 loc) • 2.47 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ElastiCacheRedis = void 0;
const aws = require("@pulumi/aws");
const pulumi = require("@pulumi/pulumi");
const common_tags_1 = require("../../shared/common-tags");
const merge_with_defaults_1 = require("../../shared/merge-with-defaults");
const defaults = {
engineVersion: '7.1',
nodeType: 'cache.t4g.micro',
parameterGroupName: 'default.redis7',
};
class ElastiCacheRedis extends pulumi.ComponentResource {
name;
vpc;
cluster;
securityGroup;
subnetGroup;
constructor(name, args, opts = {}) {
super('studion:redis:ElastiCacheRedis', name, {}, opts);
const argsWithDefaults = (0, merge_with_defaults_1.mergeWithDefaults)(defaults, args);
this.name = name;
this.vpc = pulumi.output(argsWithDefaults.vpc);
this.securityGroup = this.createSecurityGroup();
this.subnetGroup = this.createSubnetGroup();
this.cluster = this.createRedisCluster(argsWithDefaults.engineVersion, argsWithDefaults.nodeType, argsWithDefaults.parameterGroupName, argsWithDefaults.tags);
this.registerOutputs();
}
createRedisCluster(engineVersion, nodeType, parameterGroupName, tags) {
return new aws.elasticache.Cluster(`${this.name}-cluster`, {
engine: 'redis',
engineVersion: engineVersion,
nodeType: nodeType,
numCacheNodes: 1,
securityGroupIds: [this.securityGroup.id],
subnetGroupName: this.subnetGroup.name,
parameterGroupName: parameterGroupName,
port: 6379,
tags: { ...common_tags_1.commonTags, ...tags },
}, { parent: this });
}
createSubnetGroup() {
return new aws.elasticache.SubnetGroup(`${this.name}-subnet-group`, {
subnetIds: this.vpc.isolatedSubnetIds,
tags: common_tags_1.commonTags,
}, { parent: this });
}
createSecurityGroup() {
return new aws.ec2.SecurityGroup(`${this.name}-security-group`, {
vpcId: this.vpc.vpcId,
ingress: [
{
protocol: 'tcp',
fromPort: 6379,
toPort: 6379,
cidrBlocks: [this.vpc.vpc.cidrBlock],
},
],
tags: common_tags_1.commonTags,
}, { parent: this });
}
}
exports.ElastiCacheRedis = ElastiCacheRedis;