-
Notifications
You must be signed in to change notification settings - Fork 3
/
resources.tf
83 lines (71 loc) · 2.37 KB
/
resources.tf
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
resource "digitalocean_tag" "main" {
name = "tailscale-exit-node"
}
# Create a new SSH key
resource "digitalocean_ssh_key" "main" {
name = "Tailscale Exit Node SSH Key"
public_key = file(var.ssh_key_pub)
}
# Create a new Droplet
resource "digitalocean_droplet" "main" {
image = "debian-12-x64"
name = "tailscale-xn-001"
region = "ams3"
size = "s-1vcpu-1gb"
ssh_keys = [digitalocean_ssh_key.main.fingerprint]
tags = [digitalocean_tag.main.id]
connection {
type = "ssh"
user = "root"
host = self.ipv4_address
private_key = file(var.ssh_key)
}
# Install and configure tailscale
provisioner "remote-exec" {
inline = [
# wait for other droplet initial processes to finish",
"sleep 20",
# https://tailscale.com/download/linux/debian-bookworm
"curl -fsSL https://pkgs.tailscale.com/stable/debian/bookworm.noarmor.gpg | sudo tee /usr/share/keyrings/tailscale-archive-keyring.gpg >/dev/null",
"curl -fsSL https://pkgs.tailscale.com/stable/debian/bookworm.tailscale-keyring.list | sudo tee /etc/apt/sources.list.d/tailscale.list",
"sudo apt-get update -y",
"sudo apt-get install tailscale -y",
# https://tailscale.com/kb/1103/exit-nodes/#configuring-an-exit-node
"echo 'net.ipv4.ip_forward = 1' | sudo tee -a /etc/sysctl.d/99-tailscale.conf",
"echo 'net.ipv6.conf.all.forwarding = 1' | sudo tee -a /etc/sysctl.d/99-tailscale.conf",
"sudo sysctl -p /etc/sysctl.d/99-tailscale.conf",
"sudo tailscale up --advertise-exit-node --authkey=${var.tailscale_key}"
]
}
}
resource "digitalocean_firewall" "tailscale" {
depends_on = [
digitalocean_droplet.main
]
name = "only-tailscale"
tags = [digitalocean_tag.main.id]
inbound_rule {
protocol = "udp"
port_range = "3478"
source_addresses = ["100.64.0.0/10"]
}
inbound_rule {
protocol = "udp"
port_range = "41641"
source_addresses = ["100.64.0.0/10"]
}
outbound_rule {
protocol = "tcp"
port_range = "1-65535"
destination_addresses = ["0.0.0.0/0", "::/0"]
}
outbound_rule {
protocol = "udp"
port_range = "1-65535"
destination_addresses = ["0.0.0.0/0", "::/0"]
}
outbound_rule {
protocol = "icmp"
destination_addresses = ["0.0.0.0/0", "::/0"]
}
}