-
Notifications
You must be signed in to change notification settings - Fork 27
/
index.ts
70 lines (63 loc) · 2.26 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import * as aws from "@pulumi/aws";
import * as k8s from "@pulumi/kubernetes";
import * as pulumi from "@pulumi/pulumi";
import * as random from "@pulumi/random";
import { config } from "./config";
const projectName = pulumi.getProject();
const privateSubnetIds = config.privateSubnetIds;
const securityGroupIds = config.securityGroupIds;
const clusterName = config.clusterName;
// Generate a strong password for the Postgres DB.
const password = new random.RandomPassword(`${projectName}-password`, {
length: 16,
overrideSpecial: "_%@",
special: true,
}).result;
// Create a Postgres DB instance of RDS.
const dbSubnets = new aws.rds.SubnetGroup(`${projectName}-subnets`, {
subnetIds: privateSubnetIds
});
const db = new aws.rds.Instance("postgresdb", {
engine: "postgres",
instanceClass: "db.t2.micro",
allocatedStorage: 20,
dbSubnetGroupName: dbSubnets.id,
vpcSecurityGroupIds: securityGroupIds,
name: "testdb",
username: "alice",
password: password,
skipFinalSnapshot: true,
});
// Create a Secret from the DB connection information.
const provider = new k8s.Provider("provider", {kubeconfig: config.kubeconfig});
const dbConn = new k8s.core.v1.Secret("postgres-db-conn",
{
data: {
host: db.address.apply(addr => Buffer.from(addr).toString("base64")),
port: db.port.apply(port => Buffer.of(port).toString("base64")),
username: db.username.apply(user => Buffer.from(user).toString("base64")),
password: password.apply(pass => Buffer.from(pass).toString("base64")),
},
},
{provider: provider},
);
// Create a Redis instance.
const cacheSubnets = new aws.elasticache.SubnetGroup(`${projectName}-cache-subnets`, {
subnetIds: privateSubnetIds,
});
const cacheCluster = new aws.elasticache.Cluster("cachecluster", {
engine: "redis",
nodeType: "cache.t2.micro",
numCacheNodes: 1,
subnetGroupName: cacheSubnets.id,
securityGroupIds: securityGroupIds,
});
// Create a ConfigMap from the cache connection information.
const cacheConn = new k8s.core.v1.ConfigMap("postgres-db-conn",
{
data: {
host: cacheCluster.cacheNodes[0].address.apply(addr => Buffer.from(addr).toString("base64")),
},
},
{provider: provider},
);