merge files from the blockchain infra repo (#59)

This commit is contained in:
autistic-symposium-helper 2024-11-17 17:03:20 -08:00 committed by GitHub
parent 23f56ef195
commit 2a6449bb85
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
346 changed files with 29097 additions and 132 deletions

View file

@ -0,0 +1,75 @@
import cdk = require("@aws-cdk/core");
import ec2 = require("@aws-cdk/aws-ec2");
import msk = require("@aws-cdk/aws-msk");
interface MSKStackProps extends cdk.StackProps {
vpc: ec2.IVpc;
}
export class MskClusterStack extends cdk.Stack {
private vpc: ec2.IVpc;
constructor(scope: cdk.Construct, id: string, props?: MSKStackProps) {
super(scope, id, props);
const current_env = this.node.tryGetContext("env.type");
//****************************** Context variables **************************************//
const clusterName = this.node.tryGetContext("msk.DevMskCluster");
const clusterTag = this.node.tryGetContext("msk.mskClusterTag");
const brokerNodeGroupBrokerAzDistribution = this.node.tryGetContext("msk.brokerNodeGroupBrokerAzDistribution");
const brokerNodeGroupEBSVolumeSize = this.node.tryGetContext("msk.brokerNodeGroupEBSVolumeSize");
const brokerNodeGroupInstanceType = this.node.tryGetContext("msk.brokerNodeGroupInstanceType");
const brokerPort = this.node.tryGetContext("msk.brokerPort");
const kafkaVersion = this.node.tryGetContext("msk.kafkaVersion");
const numberOfBrokerNodes = this.node.tryGetContext("msk.numberOfBrokerNodes");
const enhancedMonitoring = this.node.tryGetContext("msk.enhancedMonitoring");
//**************************************** VPC
if (props)
this.vpc = props.vpc;
else
this.vpc = ec2.Vpc.fromLookup(this, current_env+"Vpc", {
vpcName: "VPCStack/"+current_env+"Vpc"
});
//**************************************** SG
const description = "Allow access to "+current_env+" MSK Cluster";
const SecurityGroup = new ec2.SecurityGroup(
this,
current_env+"MskClusterSG",
{
vpc: this.vpc,
securityGroupName: current_env+"MskClusterSG",
description: description,
allowAllOutbound: true
}
);
SecurityGroup.addIngressRule(
ec2.Peer.anyIpv4(),
ec2.Port.tcp(brokerPort),
description
);
//******************************* MSK Cluster **************************//
const cluster = new msk.CfnCluster(this, "MskCluster", {
brokerNodeGroupInfo: {
clientSubnets: this.vpc.privateSubnets.map(x => x.subnetId),
instanceType: brokerNodeGroupInstanceType,
brokerAzDistribution: brokerNodeGroupBrokerAzDistribution,
storageInfo: {
ebsStorageInfo: {
volumeSize: brokerNodeGroupEBSVolumeSize
}
}
},
clusterName: clusterName,
kafkaVersion: kafkaVersion,
numberOfBrokerNodes: numberOfBrokerNodes,
enhancedMonitoring: enhancedMonitoring,
tags: {
name: current_env+clusterTag,
}
});
}
}

View file

@ -0,0 +1,19 @@
import cdk = require('@aws-cdk/core');
import ec2 = require("@aws-cdk/aws-ec2");
export class VPCStack extends cdk.Stack {
readonly Vpc: ec2.IVpc;
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const current_env = this.node.tryGetContext("env.type");
const vpc_cidr = this.node.tryGetContext("vpc.cidr");
const vpc_maxAzs = this.node.tryGetContext("vpc.maxAzs");
const vpc = new ec2.Vpc(this, current_env+"Vpc", {
cidr: vpc_cidr,
maxAzs: vpc_maxAzs
});
this.Vpc = vpc;
}
}