-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack.ts
61 lines (53 loc) · 1.66 KB
/
stack.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
import * as cdk from "npm:aws-cdk-lib";
import {
Instance,
InstanceType,
IpAddresses,
MachineImage,
SubnetType,
UserData,
Vpc,
} from "npm:aws-cdk-lib/aws-ec2";
import { Construct } from "npm:constructs";
export interface ExitNodeProps extends cdk.StackProps {
tailscaleAuthKey: string;
exitNodeName: string;
}
export class TailscaleExitnodesCdkStack extends cdk.Stack {
constructor(scope: Construct, id: string, props: ExitNodeProps) {
super(scope, id, props);
const vpc = new Vpc(this, "TheVPC", {
ipAddresses: IpAddresses.cidr("10.0.0.0/16"),
natGateways: 0,
subnetConfiguration: [
{
cidrMask: 24,
name: "tailscale",
subnetType: SubnetType.PUBLIC,
},
],
});
const publicSubnets = vpc.selectSubnets({
subnetType: SubnetType.PUBLIC,
});
const machineImage = MachineImage.fromSsmParameter(
"/aws/service/canonical/ubuntu/server/jammy/stable/current/amd64/hvm/ebs-gp2/ami-id"
);
const userData = UserData.forLinux();
userData.addCommands(
"echo 'net.ipv4.ip_forward = 1' | sudo tee -a /etc/sysctl.conf",
"echo 'net.ipv6.conf.all.forwarding = 1' | sudo tee -a /etc/sysctl.conf",
"sysctl -p /etc/sysctl.conf",
"curl -fsSL https://tailscale.com/install.sh | sh",
`tailscale up --authkey ${props.tailscaleAuthKey} --advertise-exit-node --hostname=${props.exitNodeName}`
);
new Instance(this, "exitNode", {
instanceType: new InstanceType("t2.micro"),
vpc: vpc,
instanceName: props.exitNodeName,
vpcSubnets: publicSubnets,
machineImage: machineImage,
userData: userData,
});
}
}