forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
98 lines (78 loc) · 2.68 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as awscloud from "@pulumi/cloud-aws";
let config = new pulumi.Config("airflow");
const dbPassword = config.require("dbPassword");
let securityGroupIds = [ awscloud.getCluster()!.securityGroupId! ];
let dbSubnets = new aws.rds.SubnetGroup("dbsubnets", {
subnetIds: awscloud.getNetwork().subnetIds,
});
let db = new aws.rds.Instance("postgresdb", {
engine: "postgres",
instanceClass: "db.t2.micro",
allocatedStorage: 20,
dbSubnetGroupName: dbSubnets.id,
vpcSecurityGroupIds: securityGroupIds,
name: "airflow",
username: "airflow",
password: dbPassword,
skipFinalSnapshot: true,
});
let cacheSubnets = new aws.elasticache.SubnetGroup("cachesubnets", {
subnetIds: awscloud.getNetwork().subnetIds,
});
let cacheCluster = new aws.elasticache.Cluster("cachecluster", {
clusterId: "cache-" + pulumi.getStack(),
engine: "redis",
nodeType: "cache.t2.micro",
numCacheNodes: 1,
subnetGroupName: cacheSubnets.id,
securityGroupIds: securityGroupIds,
});
let environment = {
"POSTGRES_HOST": db.endpoint.apply(e => e.split(":")[0]),
"POSTGRES_PASSWORD": dbPassword,
"REDIS_HOST": cacheCluster.cacheNodes.apply(n => n[0].address),
"EXECUTOR": "Celery",
};
let airflowController = new awscloud.Service("airflowcontroller", {
containers: {
"webserver": {
build: "./airflow-container",
ports: [{ port: 8080, external: true, protocol: "http" }],
environment: environment,
command: [ "webserver" ],
},
"scheduler": {
build: "./airflow-container",
environment: environment,
command: [ "scheduler" ],
},
},
replicas: 1,
});
let airflower = new awscloud.Service("airflower", {
containers: {
// If the container is named "flower", we create environment variables that start
// with `FLOWER_` and Flower tries and fails to parse them as configuration.
"notflower": {
build: "./airflow-container",
ports: [{ port: 5555, external: true, protocol: "http" }],
environment: environment,
command: [ "flower" ],
},
},
});
let airflowWorkers = new awscloud.Service("airflowworkers", {
containers: {
"worker": {
build: "./airflow-container",
environment: environment,
command: [ "worker" ],
memory: 1024,
},
},
replicas: 3,
});
export let airflowEndpoint = airflowController.defaultEndpoint.apply(e => e.hostname);
export let flowerEndpoint = airflower.defaultEndpoint.apply(e => e.hostname);