generated from cloudposse/terraform-example-module
-
Notifications
You must be signed in to change notification settings - Fork 6
/
userdata.sh.tmpl
27 lines (22 loc) · 991 Bytes
/
userdata.sh.tmpl
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
#!/bin/bash -ex
exec > >(tee /var/log/user-data.log | logger -t user-data -s 2>/dev/console) 2>&1
# Enable ip_forward to allow advertising routes
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
sudo sysctl -p /etc/sysctl.conf
# Install tailscale
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://pkgs.tailscale.com/stable/amazon-linux/2/tailscale.repo
sudo yum install -y tailscale
# Setup tailscale
sudo systemctl enable --now tailscaled
# Wait a few for tailscaled to come up
sleep 5
# Start tailscale
# We pass --advertise-tags below even though the authkey being created with those tags should result
# in the same effect. This is to be more explicit because tailscale tags are a complicated topic.
sudo tailscale up \
--advertise-routes=${routes} \
--advertise-tags=${tags} \
--authkey=${authkey} \
--hostname=${hostname}%{ if ssh_enabled == true } --ssh%{ endif }