This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.ts
73 lines (63 loc) · 1.81 KB
/
server.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
import { Droplet, Firewall } from '@pulumi/digitalocean';
import {
ComponentResource,
ComponentResourceOptions,
Config,
Input,
Output,
ResourceOptions,
} from '@pulumi/pulumi';
const config = new Config();
interface Args {
// The name for the server
name: Input<string>;
// The size slug for the server
size: Input<string>;
// The ID of the VPC
vpcId: Input<string>;
}
class Server extends ComponentResource {
public readonly droplet: Output<string>;
public readonly ipv4: Output<string>;
public readonly ipv6: Output<string>;
constructor(name: string, args: Args, opts?: ComponentResourceOptions) {
super('wafflehacks:infrastructure:Server', name, { options: opts }, opts);
const defaultResourceOptions: ResourceOptions = { parent: this };
const { name: dropletName, size, vpcId } = args;
const droplet = new Droplet(
`${name}-droplet`,
{
image: '86718194', // Debian 10 x64
ipv6: true,
name: dropletName,
region: config.require('regions.digitalocean'),
size,
vpcUuid: vpcId,
},
defaultResourceOptions,
);
this.ipv4 = droplet.ipv4Address;
this.ipv6 = droplet.ipv6Address;
this.droplet = droplet.dropletUrn;
new Firewall(
`${name}-firewall`,
{
dropletIds: [droplet.id.apply((id) => parseInt(id))],
name: dropletName,
inboundRules: [80, 443].map((port) => ({
portRange: port.toString(),
protocol: 'tcp',
sourceAddresses: ['0.0.0.0/0', '::/0'],
})),
outboundRules: ['tcp', 'udp'].map((protocol) => ({
portRange: '1-65535',
protocol,
destinationAddresses: ['0.0.0.0/0', '::/0'],
})),
},
defaultResourceOptions,
);
this.registerOutputs();
}
}
export default Server;