-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
136 lines (119 loc) · 4.89 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import * as fs from "fs";
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
import * as os from "os";
interface IHashiClientOptions {
imageUrl: string,
machineType: string,
networkLink: string | pulumi.Output<string>,
targetSize: number,
networkTier?: string,
description?: string,
labels?: pulumi.Input<{[key: string]: pulumi.Input<string>}>,
serviceAccountName?: string,
tags?: Array<string>,
zone?: string,
domain?: string
}
export default class HashiClient extends pulumi.ComponentResource {
public regionalAddress: pulumi.Output<string>;
public globalAddress: pulumi.Output<string>;
constructor(name: string, options: IHashiClientOptions) {
super("c9s:component:HashiClient", name);
options = {
networkTier: "STANDARD",
description: "Created by Pulumi",
labels: {},
serviceAccountName: "c9s-bot",
tags: ["allow-icmp"],
zone: "us-central1-a",
domain: "mydomain.com",
...options
};
const instanceTemplate = this.instanceTemplate(options);
const targetPool = new gcp.compute.TargetPool("client-pool", {}, { parent: this });
const instanceGroupManager = this.instanceGroupManager(instanceTemplate.selfLink, targetPool.selfLink, options.targetSize);
const globalAddress = new gcp.compute.GlobalAddress("client-global-address", {}, { parent: this });
const sslCertificate = new gcp.compute.MangedSslCertificate("cert", {
managed: {
domains: options.domain,
},
}, { parent: this });
const ipAddress = new gcp.compute.Address("client-ip-address", {
networkTier: options.networkTier,
}, { parent: this });
const healthCheck = new gcp.compute.HttpHealthCheck("client-health-check", {
port: 9999,
requestPath: "/health",
}, { parent: this });
const backendService = new gcp.compute.BackendService("client-backend", {
backends: [{
group: instanceGroupManager.instanceGroup,
}],
healthChecks: healthCheck.selfLink,
portName: "fabio",
protocol: "HTTP",
}, { parent: this });
const urlMap = new gcp.compute.URLMap("client-url-map", {
defaultService: backendService.selfLink
}, { parent: this });
const targetHttpsProxy = new gcp.compute.TargetHttpsProxy("client", {
sslCertificates: [sslCertificate.selfLink],
urlMap: urlMap.selfLink,
}, { parent: this});
const globalForwardingRule = new gcp.compute.GlobalForwardingRule("client-region", {
ipAddress: globalAddress.address,
portRange: "443",
target: targetHttpsProxy.selfLink,
}, { parent: this });
const forwardingRule = new gcp.compute.ForwardingRule("client-http-forwarding-rule", {
ipAddress: ipAddress.address,
networkTier: options.networkTier,
portRange: "4646",
target: targetPool.selfLink,
}, { parent: this });
this.regionalAddress = ipAddress.address;
this.globalAddress = globalAddress.address;
this.registerOutputs({
regionalAddress: this.regionalAddress,
globalAddress: this.globalAddress
});
}
instanceTemplate(options: IHashiClientOptions): gcp.compute.InstanceTemplate {
return new gcp.compute.InstanceTemplate("client", {
disks: [{
autoDelete: true,
boot: true,
sourceImage: options.imageUrl,
}],
instanceDescription: options.description,
labels: options.labels,
machineType: options.machineType,
metadataStartupScript: fs.readFileSync(`${__dirname}/files/startup.sh`, "utf-8"),
networkInterfaces: [{
network: options.networkLink,
}],
serviceAccount: {
email: `${options.serviceAccountName}@assetstore.iam.gserviceaccount.com`,
scopes: ["compute-ro"],
},
tags: options.tags,
}, { parent: this });
};
instanceGroupManager(instanceTemplateLink: string | pulumi.Output<string>, targetPoolLink: string | pulumi.Output<string>, targetSize: number) {
return new gcp.compute.InstanceGroupManager("client-group-manager", {
baseInstanceName: "client",
versions: [{
instanceTemplate: instanceTemplateLink,
name: "live"
}],
waitForInstances: true,
namedPorts: [{
name: "fabio",
port: 9999,
}],
targetPools: [targetPoolLink],
targetSize: targetSize,
}, { parent: this });
}
}